#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll permutation[13] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600};
ll Derangement_Number(int n)
{
int d[n+1], i;
d[0] = 1;
d[1] = 0;
d[2] = 1;
for(i=3;i<=n;i++)
d[i] = (i-1) * (d[i-1] + d[i-2]);
return d[n];
}
int main()
{
int t, n;
cin >> t;
while(t--)
{
cin >> n;
ll r = Derangement_Number(n);
cout << r << "/" << permutation[n] << "\n";
}
return 0;
}
#define ll long long int
using namespace std;
ll permutation[13] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600};
ll Derangement_Number(int n)
{
int d[n+1], i;
d[0] = 1;
d[1] = 0;
d[2] = 1;
for(i=3;i<=n;i++)
d[i] = (i-1) * (d[i-1] + d[i-2]);
return d[n];
}
int main()
{
int t, n;
cin >> t;
while(t--)
{
cin >> n;
ll r = Derangement_Number(n);
cout << r << "/" << permutation[n] << "\n";
}
return 0;
}
Comments
Post a Comment