QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389184#7954. Special Numberskevinyang#WA 0ms3884kbC++172.7kb2024-04-14 04:44:232024-04-14 04:44:23

Judging History

你现在查看的是最新测评结果

  • [2024-04-14 04:44:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3884kb
  • [2024-04-14 04:44:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = (int)1e9+7;
pair<int,int> get(int n, int x){
	int v = 0;
	while(n%x==0){
		v++;
		n/=x;
	}
	return make_pair(n,v);
}
vector<int>p = {2,3,5,7};
vector<int>sz;
int k;
vector<int>factors;
map<int,int>dp[25][2]; // length, equals so far
int solve(string s){
	for(int i = 0; i<25; i++){
		dp[i][0].clear();
		dp[i][1].clear();
	}
	dp[0][1][1] = 1;
	s = " " + s;
	for(int t = 1; t<s.size(); t++){
		for(int d = 0; d<10; d++){
			for(int u: factors){
				dp[t][0][__gcd(u*d,k)] += dp[t-1][0][u]; dp[t][0][__gcd(u*d,k)]%=mod;

			}
			if(t > 1 && d > 0){
				dp[t][0][__gcd(d,k)]++;
				dp[t][0][__gcd(d,k)]%=mod;
				//cout <<  "upd " << t << ' ' << __gcd(d,k) << ' ' << dp[t][0][__gcd(d,k)] << '\n';
			}
		}
		for(int d = 0; d<=s[t]-'0'; d++){
			//cout << "trying " << d << '\n';
			if(d==0 && t==1)continue;
			if(d<s[t]-'0'){
				for(int u: factors){
					dp[t][0][__gcd(u*d,k)] += dp[t-1][1][u]; dp[t][0][__gcd(u*d,k)]%=mod;
				}
			}
			else{
				for(int u: factors){
					dp[t][1][__gcd(u*d,k)] += dp[t-1][1][u]; dp[t][1][__gcd(u*d,k)]%=mod;
				}
			}
		}
	}
	/*
	if(s.size() >= 3)for(auto [a,b] : dp[3][0]){
		cout << a << ' ' << b << '\n';
	}
	if(s.size() >= 3)for(auto [a,b] : dp[2][0]){
		cout << a << ' ' << b << ' ' << 1 << '\n';
	}
	if(s.size() >= 3)for(auto [a,b] : dp[1][0]){
		cout << a << ' ' << b << ' ' << -1 << '\n';
	}
	*/
	int ans = dp[s.size()-1][0][k] + dp[s.size()-1][1][k];
	//cout << ans << '\n';
	return ans%mod;
}
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	cin >> k;
	int k2 = k;
	for(int i = 0; i<4; i++){
		auto [nk, cnt] = get(k2,p[i]);
		sz.push_back(cnt);
		k2 = nk;
	}
	for(int a = 0; a<=sz[0]; a++){
		for(int b = 0; b<=sz[1]; b++){
			for(int c = 0; c<=sz[2]; c++){
				for(int d = 0; d<=sz[3]; d++){
					int v = 1;
					for(int i = 0; i<a; i++){
						v*=2;
					}
					for(int i = 0; i<b; i++){
						v*=3;
					}
					for(int i = 0; i<c; i++){
						v*=5;
					}
					for(int i = 0; i<d; i++){
						v*=7;
					}
					factors.push_back(v);
				}
			}
		}
	}
	sort(factors.begin(),factors.end());
	/*
	cerr << k2 << '\n';
	cerr << "gay\n";
	
	for(int nxt: factors){
		cout << nxt << ' ';
	}
	cout << '\n' << '\n';
	*/
	if(k2!=1){
		cout << "0\n";
		return 0;
	}
	string l,r;
	cin >> l >> r;
	for(int i = (int)l.size()-1; i>=0; i--){
		if(l[i] == '0'){
			l[i] = '9';
			continue;
		}
		l[i]--;
		break;
	}
	if(l[0] == '0'){
		l.erase(l.begin());
	}
	int v = solve(r);
	int v2 = solve(l);
	//cout << v << ' ' << v2 << '\n';
	v-=v2;
	v%=mod;
	v+=mod; v%=mod;
	cout << v << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3624kb

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3656kb

input:

1 1 1

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'