蒟蒻60分求助
查看原帖
蒟蒻60分求助
1142179
Main_Lid楼主2024/12/20 20:39
#include<bits/stdc++.h>
using namespace std;
int l,r;
const int mod=1e7+7;
int f[110][110],a[110];
int len;
int d;
int t;
int dfs1(int pos,int pre,int sim)
{
	if(pos==0)return (max(pre,1));
	if(!sim&&f[pos][pre]!=-1)return f[pos][pre];
	long long res=1,up=sim?a[pos]:1;
	for(int i=0;i<=up;i++)
	{
		res*=dfs1(pos-1,pre+(i==1),sim&&i==up);
		res%=mod;
	}
	
	return (sim?res:f[pos][pre]=res);
}
int c1(long long x)
{
	memset(f,-1,sizeof f);
	len=0;
	while(x)
	{
		a[++len]=x%2;
		x/=2;
	}
	return dfs1(len,0,1);
}
signed main()
{
	cin>>r;
	cout<<c1(r);
	return 0;
}
2024/12/20 20:39
加载中...