求助数位DP
查看原帖
求助数位DP
119261
7KByte楼主2020/7/26 17:46

Rt,NN大了就会WA,不知道为什么。

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define N 64
#define P 10000007LL
using namespace std;
typedef long long ll;
ll f[N][2],n,c[N][N];
void prework(){
	c[0][0]=1;
	rep(i,1,60){
		c[i][0]=1;
		rep(j,1,i)c[i][j]=(c[i-1][j-1]+c[i-1][j])%P;
	}
}
ll Pow(ll x,ll y){
	//cout<<x<<" "<<y<<endl;
	ll now=1;
	for(;y;y>>=1,x=x*x%P)if(y&1)now=now*x%P;
	return now;
}
ll solve(){
	ll t=0,m=n;
	f[0][0]=f[0][1]=1;
	while(m){
		t++;
		f[t][0]=f[t-1][0]*f[t-1][1]%P;
		ll sum=1;
		rep(i,0,t-1)sum=Pow(i+1,c[t-1][i])*sum%P;
		f[t][1]=sum;
		m>>=1;
	}
	ll ans=f[t][0],s=1;
	pre(i,t-1,1){
		if(n&(1LL<<(i-1))){
			rep(j,0,i-1)ans=ans*Pow(s+j,c[i-1][j])%P;
			s++;
		}
	}
	return ans;
}
int main(){
	prework();
	scanf("%lld",&n);n++;
	printf("%lld\n",solve());
	return 0;
}
2020/7/26 17:46
加载中...