XOR on Pascal
Topic : Xor + combinatorics + Bigmod
Solution:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
typedef long long ll; | |
const ll Max = 100005; | |
ll MOD = 1000000007; | |
ll factorial[Max]; | |
ll BigMod(ll N, ll POW, ll mod) | |
{ | |
if(POW == 0)return 1; | |
if(POW&1)return ((N%mod) * BigMod(N, POW - 1, mod)) % mod; | |
else{ | |
ll d = BigMod(N, POW/2, mod); | |
return ((d%mod) * (d%mod)) % mod; | |
} | |
} | |
void fact() | |
{ | |
factorial[1] = 1; | |
for(ll i = 2; i < Max; i++){ | |
factorial[i] = (i*factorial[i-1]) % MOD; | |
} | |
} | |
int main() | |
{ | |
/* | |
#ifndef ONLINE_JUDGE | |
freopen("in.txt", "r", stdin); | |
freopen("out.txt", "w", stdout); | |
#endif | |
*/ | |
//double start_time = clock(); | |
fact(); | |
int t; | |
cin >> t; | |
while(t--){ | |
ll n; | |
cin >> n; | |
if(n == 0)cout << 1 <<endl; | |
else if(n&1)cout << 0 << endl; | |
else{ | |
ll r = ((factorial[n/2] % MOD) * (factorial[n/2]%MOD) ) %MOD; | |
cout << (factorial[n] * BigMod(r, MOD-2, MOD) % MOD)<<endl; | |
} | |
} | |
//double end_time = clock(); | |
//printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000); | |
return 0; | |
} |
No comments:
Post a Comment