花神的数论题(数位dp)

时间:2023-03-08 22:36:20
花神的数论题(数位dp)

规定sum[i] 为i里面含1的个数 ,求从1-N sum[i]的乘积。

数为64位内的,也就是sum[i]<=64的,这样可以dp求出1-N中含k个1的数有多少个,快速幂一下就可以了。

有个地方没开LL ,WA了几次。

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define LL long long
#define mod 10000007
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
LL dp[][][];
int di[];
LL dfs(int i,bool e,int k,int s)
{
if(i==-) return k==s;
if(!e&&~dp[i][k][s]) return dp[i][k][s];
int mk = e?di[i]:;
LL ans = ;
for(int j = ; j <= mk ; j++)
{
ans = ans+dfs(i-,e&&(j==mk),k,s+j);
}
return e?ans:dp[i][k][s] = ans;
}
LL exp_mod(int a,LL n)
{
LL t;
if(n==) return ;
if(n==) return a;
t = exp_mod(a,n/);
t = (t*t)%mod;
if(n&) t = (t*a)%mod;
return t;
}
LL cal(LL n)
{
int g=;
while(n)
{
di[g++] = n%;
n/=;
}
LL ans = ;
for(int i = ;i <= g ; i++)
{
LL num = dfs(g-,,i,);
ans = (ans*exp_mod(i,num))%mod;
}
return ans;
}
int main()
{
LL n;
memset(dp,-,sizeof(dp));
while(cin>>n)
{
cout<<cal(n)<<endl;
}
return ;
}