QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#389155#7954. Special NumbersFOY#WA 0ms3856kbC++231.2kb2024-04-14 03:40:132024-04-14 03:40:14

Judging History

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

  • [2024-04-14 03:40:14]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2024-04-14 03:40:13]
  • 提交

answer

#include <iostream>
#include <vector>
#include <map>
#include <numeric>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

void fix(ll &i) {
	i %= mod;
	if (i < 0) i += mod;
	i %= mod;
}

ll count(ll k, string up) {
	map<ll, ll> hi, lo;
	for (int i = 1; i < up[0]-'0'; i++) {
		lo[gcd(i, k)%k] += 1;
	}
	hi[gcd(up[0]-'0', k)%k] += 1;
	for (int i = 1; i < up.size(); i++) {
		map<ll, ll> nhi, nlo;
		for (int j = 0; j <= 9; j++) {
			for (auto [g, cnt] : hi) {
				if (j == up[i]-'0') {
					fix(nhi[gcd(g*j, k)%k] += cnt);
				}
				else if (j < up[i] -'0') {
					fix(nlo[gcd(g*j, k)%k] += cnt);
				}
			}

			for (auto [g, cnt] : lo) {
				fix(nlo[gcd(g*j, k)%k] += cnt);
			}
		}
		hi = nhi;
		lo = nlo;
	}
	return (hi[0] + lo[0])%mod;
}

ll countAll(ll k, string r) {
	ll out = count(k, r);
	string s = "9";
	while (s.size() < r.size()) {
		fix(out += count(k, s));
		s.push_back('9');
	}
	return out;
}

int main() {
	ll k; cin >> k;
	string l, r; cin >> l >> r;
	ll out = countAll(k, r);
	if (l != "1") {
		int i = l.size()-1;
		while (l[i] == '0') {
			l[i] = '9';
			i--;
		}
		l[i]--;
		fix(out -= countAll(k, l));
	}
	cout << out << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

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

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 100 100000

output:

99801

result:

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