题目
洛谷
数学方法学不会%>_<%
做法
爆搜二进制下存在\(i\)位\(1\)的情况,然后快速幂乘起来
My complete code
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL p=10000007;
LL n;
LL f[51][51][2][51],a[51],ans[51];
LL Dfs(LL now,LL num,LL top,LL need){
if(!now) return need==num;
if(~f[now][num][top][need]) return f[now][num][top][need];
LL Up=top?a[now]:1;
LL ret(0);
for(LL i=0;i<=Up;++i)
ret+=Dfs(now-1,num+(i==1),top&&(i==Up),need);
return f[now][num][top][need]=ret;
}
inline LL Pow(LL base,LL b){
LL ret(1);
while(b){
if(b&1) ret=(ret*base)%p;
base=(base*base)%p, b>>=1;
}return ret;
}
inline LL Solve(LL n){
LL tot(0);
while(n) a[++tot]=n&1,n>>=1;memset(f,-1,sizeof(f));
for(LL i=1;i<=50;++i) ans[i]=Dfs(tot,0,1,i);
LL ret(1);
for(LL i=1;i<=50;++i) ret=(ret*Pow(i,ans[i]))%p;
return ret;
}
int main(){
cin>>n;
cout<<Solve(n);
return 0;
}