Description
Background
As we all know, the flower God over the years by virtue of the boundless power of the big OJ, OI, CF, TC ... Of course it also includes CH.
Describe
The flower God comes to lecture again this day. After class, there is a very difficult god problem. I waited for Konjac Konjac to suffer again.
The topic of the flower God is this
Set sum (i) to indicate the number of 1 in the binary representation of I. Give a positive integer N, the flower God wants to ask you
Pie (sum (i)), which is the product of sum (1)-sum (N).
Input
A positive integer N.
Output
A number, the value of the answer modulus 10000007.
Sample Input
Sample Input One
3
Sample Output
Sample Output One
2
HINT
For example one, 1*1*2=2;
Data scope and conventions
For 100% of data, n≤10^15
Idea: Digital DP, calculate the number of I with less than N and sum (i) =k, set to u, then the answer is POW (k,u), then enumerate K
#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
#define MAXN 1000005
#define MOD 10000007
using namespace Std;
Long Long num[maxn],h=0,dp[100][100][100][2];
Long long Pos,long long Need,long long Now,long long limit)
{
if (pos==0) return now==need;
int tmp=limit?num[pos]:1;
Long Long ans=0;
if (!limit&&dp[pos][need][now][limit]!=-1)
return Dp[pos][need][now][limit];
for (int i=0;i<=tmp;i++)
{
Ans= (Ans+dfs (pos-1,need,now+i,limit&& (i==tmp)));
}
if (!limit)
Dp[pos][need][now][limit]=ans;
return ans;
}
Long Long Mpow (long long A,long long N)
{
Long Long Ans=1;
A%=mod;
while (n)
{
if (n%2) ans= (ans%mod) * (A%mod)%mod;
n/=2;
A= (a%mod) * (A%mod)%mod;
}
return ans;
}
int main ()
{
Long long N;
Memset (Dp,-1,sizeof (DP));
while (scanf ("%lld", &n)!=eof)
{
Long Long ans=1;h=0;
if (n==0) {printf ("0\n"); continue;}
while (n>0) {num[++h]=n&1;n>>=1;}
for (int i=1;i<=h;i++)
{
Long Long U=dfs (h,i,0,1);
Long Long V=mpow (long Long) i,u%9988440+9988440);
Ans= ((ans%mod) * (v%mod))%mod;
if (ans==6296768)
{
int zz=1;
}
}
printf ("%lld\n", ans);
}
return 0;
}
?
Bzoj 3209: The number topic of the flower God "digital DP"