BZOJ3209【数论】

/* I will wait for you */  
  
#include <cstdio>  
#include <cstdlib>  
#include <cstring>  
#include <cmath>  
#include <ctime>  
#include <algorithm>  
#include <iostream>  
#include <fstream>  
#include <vector>  
#include <queue>  
#include <deque>  
#include <set>  
#include <map>  
#include <string>  
#define make make_pair  
#define fi first  
#define se second  
  
using namespace std;  
  
typedef long long ll;  
typedef unsigned long long ull;  
typedef pair<int, int> pii;  
  
const int maxn =1500010;  
const int maxm = 61;  
const int maxs = 26;  
const int inf = 0x3f3f3f3f;  
const int P = 10000007;  
const double error = 1e-9;  
  
inline ll read() {  
    ll x = 0, f = 1; char ch = getchar();  
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();  
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();  
    return x * f;  
}  

ll r[maxn], b[maxn], f[maxm][maxm];

void init() {
	f[0][0] = 1;
	for (int i = 1; i < maxm; i++)
		for (int j = 0; j < maxm; j++)
			f[i][j] = (j ? f[i - 1][j - 1] : 0) + f[i - 1][j];
	
	for (int i = 0; i < maxm; i++)
		f[i][1]++;
	
	b[0] = 1;
	for (int i = 1; i < maxm; i++)
		b[i] = b[i - 1] << 1;
}

ll Pow(int a, ll b) {
	ll ans = 1, mul = a;
	
	for (; b; b >>= 1, (mul *= mul) %= P)
		if (b & 1) (ans *= mul) %= P;
	
	return ans;
}

int main() {
	ll n = read(); init();
	
	for (int i = maxm, t = 0; i >= 0; i--)
		if (n & b[i]) {
			for (int j = 1; j < maxm; j++)
				r[j + t] += f[i][j];
			t++;
		}
	
	ll ans = 1;	
	for (int i = 1; i < maxm; i++) 
		(ans *= Pow(i, r[i])) %= P;
	printf("%lld\n", ans);
	
	return 0;
}
10000007不是素数.所以用了费马小定理的我莫名WA了无数发.

你可能感兴趣的:(BZOJ3209【数论】)