UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203993#3573. 好数字lsr1001420ms395824kbC++1.8kb2024-03-31 11:44:062024-03-31 12:03:24

answer

#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int mod=1e9+7;

ll K,l,r;
ll f[20][2][2][2];
ll g[20][65][37][25][21][2];
int len;
ll maxx;
int num[33];
int cnt[5];

ll dfs(int now,int top,int limit,int bj){
	if(now==len+1) return bj;
	if(f[now][top][limit][bj]!=-1) return f[now][top][limit][bj];
	int up=limit?num[len-now+1]:9;
	ll ans=0;
	for(int i=0;i<=up;++i){
		if(top){
			if(i==0) ans=(ans+dfs(now+1,top,limit&(i==up),bj))%mod;
			else ans=(ans+dfs(now+1,0,limit&(i==up),bj))%mod;
		}else{
			ans=(ans+dfs(now+1,0,limit&(i==up),bj|(i==0)))%mod;
		}
	}
	f[now][top][limit][bj]=ans;
	return ans;
}

ll dfs1(int now,int a,int b,int c,int d,int top,int limit){
	if(now==len+1) return (a>=cnt[1]&&b>=cnt[2]&&c>=cnt[3]&&d>=cnt[4]);
	if(!top&&g[now][a][b][c][d][limit]!=-1) return g[now][a][b][c][d][limit];
	int up=limit?num[len-now+1]:9;
	ll ans=0;
	for(int i=top?0:1;i<=up;++i){
		int ii=i;
		int aa=a,bb=b,cc=c,dd=d;
		if(i==0){
			ans=(ans+dfs1(now+1,a,b,c,d,top,limit&(i==up)))%mod;
			continue;
		}
		while(ii%2==0) ii/=2,++aa;
		while(ii%3==0) ii/=3,++bb;
		while(ii%5==0) ii/=5,++cc;
		while(ii%7==0) ii/=7,++dd;
		ans=(ans+dfs1(now+1,aa,bb,cc,dd,0,limit&(i==up)))%mod;
	}
	if(!top) g[now][a][b][c][d][limit]=ans;
	return ans;
}

ll solve(ll x){
	memset(f,-1,sizeof(f));memset(g,-1,sizeof(g));
	ll ans=0;
	maxx=x;
	len=0;
	while(x){
		num[++len]=x%10;
		x/=10;
	}
	ans=(ans+dfs(1,1,1,0))%mod;
	if(K==1) ans=(ans+dfs1(1,0,0,0,0,1,1))%mod;
	return ans;
}

signed main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>K>>l>>r;
	while(K%2==0){
		K/=2;
		cnt[1]++;
	}
	while(K%3==0){
		K/=3;
		cnt[2]++;
	}
	while(K%5==0){
		K/=5;
		cnt[3]++;
	}
	while(K%7==0){
		K/=7;
		cnt[4]++;
	}
	cout<<(solve(r)-solve(l-1)+mod)%mod<<'\n';
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 131ms
memory: 395820kb

input:

70 116466 611763

output:

266010

result:

ok single line: '266010'

Test #2:

score: 10
Accepted
time: 136ms
memory: 395824kb

input:

95 57496 294301

output:

94809

result:

ok single line: '94809'

Test #3:

score: 10
Accepted
time: 110ms
memory: 395824kb

input:

35 181450 811315

output:

357942

result:

ok single line: '357942'

Test #4:

score: 10
Accepted
time: 213ms
memory: 395824kb

input:

49 390743029546281688 897369408302232836

output:

845178708

result:

ok single line: '845178708'

Test #5:

score: 10
Accepted
time: 105ms
memory: 395820kb

input:

87 416811418275915375 661550667403190015

output:

865220601

result:

ok single line: '865220601'

Test #6:

score: 10
Accepted
time: 159ms
memory: 395820kb

input:

49 263200944988346673 899021890363432388

output:

371434567

result:

ok single line: '371434567'

Test #7:

score: 10
Accepted
time: 141ms
memory: 395820kb

input:

459461362500000000 584285667371783480 593554830868481465

output:

174618705

result:

ok single line: '174618705'

Test #8:

score: 10
Accepted
time: 95ms
memory: 395824kb

input:

248267086730062075 112996836547196708 855093305228691806

output:

491236100

result:

ok single line: '491236100'

Test #9:

score: 10
Accepted
time: 187ms
memory: 395824kb

input:

240145138800000000 456743582813848465 595207312929681017

output:

30742524

result:

ok single line: '30742524'

Test #10:

score: 10
Accepted
time: 143ms
memory: 395820kb

input:

874402919588115955 114649322903363556 727551216375789495

output:

24686509

result:

ok single line: '24686509'

Extra Test:

score: 0
Extra Test Passed