QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#292128#7954. Special NumbersPhantomThreshold#WA 0ms3824kbC++171.7kb2023-12-27 19:17:462023-12-27 19:17:47

Judging History

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

  • [2023-12-27 19:17:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2023-12-27 19:17:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod=1'000'000'007;

__int128 read(){
	string str;
	cin >> str;
	__int128 ret=0;
	for (auto ch:str) ret=ret*10+(ch-'0');
	return ret;
}
void add(ll &A,ll B){A+=B;if (A>=mod) A-=mod;}
void sub(ll &A,ll B){A-=B;if (A<0) A+=mod;}

vector<ll> digit;
map<pair<ll,ll>,ll> dict;

ll dfs(ll dep,bool lead,bool lt,ll K){

//	cerr << "-------dfs()-------" << endl;
//	cerr << dep << " " << lead << " " << lt << " " << K << endl;

	if (dep==-1){
		if (K==1) return 1;
		return 0;
	}
	pair<ll,ll> PAIR=make_pair(dep,K);
	if (lead && lt && dict.count(PAIR)) return dict[PAIR];
	
	ll mx=(lt)?(9):(digit[dep]);
	
//	cerr << "mx : " << mx << endl;
	
	ll ans=0;
	for (ll i=0;i<=mx;i++){
		bool nxtlead=lead|(i!=0);
		bool nxtlt=lt|(i<digit[dep]);
		ll nxtK=K;
		if (nxtlead){
			ll g=__gcd(K,i);
			nxtK=K/g;
		}
		add(ans,dfs(dep-1,nxtlead,nxtlt,nxtK));
	}
	if (lead && lt) dict[PAIR]=ans;
//	cerr << "-----res---------" << endl;
//	cerr << dep << " " << lead << " " << lt << " " << K << endl;
//	cerr << "ans : " << ans << endl;
	
	return ans;
}

ll gao(__int128 x,ll K){
	if (x==0) return 0;
	digit.clear();
	for (;x;x/=10) digit.emplace_back(x%10);
	return dfs((int)digit.size()-1,0,0,K);
}

bool test(ll K){
	for (;K%2==0;) K/=2;
	for (;K%3==0;) K/=3;
	for (;K%5==0;) K/=5;
	for (;K%7==0;) K/=7;
	return (K==1);
}

int main(){
	ios_base::sync_with_stdio(false);
	long long K=1e17;
	cin >> K;
//	__int128 L=1;
//	__int128 R=1e20;
	
	__int128 L=read();
	__int128 R=read();
	
//	if (!test(K)) cout << 0 << "\n";
	
	ll ans=gao(R,K);
	sub(ans,gao(L-1,K)); 
	cout << ans << "\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

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

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

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

input:

1 1 1

output:

2

result:

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