蒟蒻求助,记搜70,#8wa,#9#10tle
查看原帖
蒟蒻求助,记搜70,#8wa,#9#10tle
365532
Mr_ll楼主2022/11/10 15:10
#include <iostream>
#include <cstdio>
#include <cmath> 
#include <cstring>
#include <algorithm>
#define ll long long 
using namespace std;
const int P=1e7+7;
ll n;
int c[70],f[70][70];
ll read() {
	ll x=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x;
}
ll _pow(ll a,ll b) {
	ll ans=1;
	while(b) {
		if(b&1) ans*=a,ans%=P;
		b>>=1;
		a*=a;a%=P;
	}
	return ans;
}
ll dfs(int pos,int cnt,int plan,int limit) {
	if(pos<1) return cnt==plan;
	if(!limit&&f[pos][cnt]!=-1) return f[pos][cnt]; 
	int mx=limit?c[pos]:1;
	ll ans=0;
	for(int i=0;i<=mx;i++) {
		ans+=dfs(pos-1,cnt+(i==1),plan,limit&&(i==c[pos]));
	}
	if(!limit) f[pos][cnt]=ans;
	return ans;
}
ll cl(ll x) {
	int cnt=0;
	ll ans=0;
	while(x) {
		c[++cnt]=x&1;
		x>>=1;
	}
	ans=1;
	for(int i=1;i<=cnt;i++) {
		memset(f,-1,sizeof(f));
		ans*=_pow(i,dfs(cnt,0,i,1));
		ans%=P;
	}
	return ans;
}
int main() {
	n=read();
	printf("%lld\n",cl(n));
	return 0;
}
2022/11/10 15:10
加载中...