[Solution]
Digit DP. Count numbers whose digit sum in binary equal to k.
The hole in this problem is that 10000007(10^7+7) isn't a prime.
[Code]
#include <cstdio>
#include <memory.h>
#include <algorithm>
using namespace std;
typedef long long qw;
#ifdef WIN32
#define lld "%I64d"
#else
#define lld "%lld"
#endif
const int maxn = 80;
const qw mod = 10000007;
qw f[maxn][maxn][2], a, s, n;
#define pow2(x) (1LL<<(x))
#define incm(a,b) (((a)+=(b))%=mod)
#define inc(a,b) ((a)+=(b))
qw getBit(qw x) {
qw s = 0;
while (x >>= 1)
s ++;
return s;
}
qw modPow(qw a, qw x) {
qw s = 1;
for (; x; x >>= 1, a = a * a % mod)
if (x & 1)
s = s * a % mod;
return s;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
memset(f, 0, sizeof(f));
scanf(lld, &a);
n = getBit(a);
f[0][0][0] = 1;
f[0][1][0] = 1;
f[0][0][1] = 1;
f[0][a & 1][1] = 1;
for (int i = 1; i <= n; i ++)
for (int j = 0; j <= n + 1; j ++) {
inc(f[i][j][0], f[i - 1][j][0]);
if (j)
inc(f[i][j][0], f[i - 1][j - 1][0]);
if ((a >> i) & 1) {
if (j)
inc(f[i][j][1], f[i - 1][j - 1][1]);
inc(f[i][j][1], f[i - 1][j][0]);
}
else
inc(f[i][j][1], f[i - 1][j][1]);
}
s = 1;
for (int i = 1; i <= n + 1; i ++)
s = modPow(i, f[n][i][1]) * s % mod;
printf(lld "\n", s);
}