思路:数位$DP$
提交:5次(其实之前A过,但是调了调当初的程序。本次是2次AC的)
题解:
我们分别求出$sum(x)=i$,对于一个$i$,有几个$x$,然后我们就可以快速幂解决。
至于求个数用数位$DP$就好了。
#include<cstdio> #include<iostream> #include<cstring> #define ull unsigned long long #define ll long long #define R register ll using namespace std; #define pause (for(R i=1;i<=10000000000;++i)) #define In freopen("NOIPAK++.in","r",stdin) #define Out freopen("out.out","w",stdout) namespace Fread { static char B[1<<15],*S=B,*D=B; #ifndef JACK #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++) #endif inline ll g() { R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix; if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix; } inline bool isempty(const char& ch) {return (ch<=36||ch>=127);} inline void gs(char* s) { register char ch; while(isempty(ch=getchar())); do *s++=ch; while(!isempty(ch=getchar())); } } using Fread::g; using Fread::gs; namespace Luitaryi { const int N=51,M=1e7+7; ll n; int len,num[N]; ll f[N][N]; inline int qpow(ll a,ll p) { R ret=1; a%=M; for(;p;p>>=1,(a*=a)%=M) if(p&1) (ret*=a)%=M; return ret; } inline ll dfs(int l,bool ul,int c,int d) {//l:长度,ul:上界标记,c:统计1的个数,d:所求一的个数(即我们此时令sum(x)=d) if(!l) return c==d; if(!ul&&~f[l][c]) return f[l][c]; R lim=(ul?num[l]:1),cnt=0; for(R i=0;i<=lim;++i) cnt+=dfs(l-1,ul&&i==lim,c+i,d); return ul?cnt:f[l][c]=cnt; } inline int solve(ll n) { R ans=1; for(;n;n>>=1) num[++len]=n&1; for(R i=1;i<=len;++i) memset(f,0xff,sizeof(f)), ans=(ans*qpow(i,dfs(len,true,0,i)))%M; return ans; } inline void main() { n=g(); printf("%d ",solve(n)); } } signed main() { Luitaryi::main(); return 0; }
2019.07.21