QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#797200#7954. Special Numbersfeeder1#WA 1ms3784kbC++203.6kb2024-12-02 18:57:422024-12-02 18:57:44

Judging History

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

  • [2024-12-02 18:57:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3784kb
  • [2024-12-02 18:57:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tii = tuple<int, int, int>;
using tll = tuple<ll, ll, ll>;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"
#define all(v) v.begin(),v.end()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); 
constexpr int maxn = 1e6 + 5;
constexpr ll mod = 1e9 + 7;
constexpr int C = 21;

ll n, m, q, k, t, a, b, c;
ll pw[C];

unordered_map<ull, ull> cnt2[C]; 
ull cnt[C];

ull compute2(ull val, int idx) {
    auto& m = cnt2[idx];
    auto it = m.find(val);
    if (it != m.end()) {
        return it->second;
    }

    ull ans = 0;
    ans += pw[idx];
    for (ull i = 1; i <= 9; i++) {
        ull g = __gcd(val, i);
        ull rem = val / g;

        if (idx > 0) 
            ans += compute2(rem, idx - 1);
        else {
            if (rem == 1) ans++;
        }
    }

    ans %= mod;
    cnt2[idx][val] = ans;
    return ans;
}

ull compute(ull val, int idx) {
    ull ans = 0;
    for (ull i = 1; i <= 9; i++) {
        ull g = __gcd(val, i);
        if (idx > 0) {
            ans += compute2(val / g, idx - 1);
            ans %= mod;
        }
        else {
            if (val / g == 1) ans++;
        }
    }

    if (idx > 0) ans += cnt[idx - 1];
    else ans++;

    return ans % mod;
}

void precomp() {
    pw[0] = 1;
    for (int i = 1; i < C; i++) {
        pw[i] = pw[i - 1] * 10 % mod;
    }
    for (int i = 0; i < C; i++) {
        cnt[i] = compute(k, i);
    }
}

ull string_to_val(const string& s, int idx) {
    ull ans = 0;
    for (int i = idx; i >= 0; i--) {
        auto it = s[i];
        ans *= 10;
        ans += it - '0';
        ans %= mod;
    }

    ans = (ans + 1) % mod;
    return ans;
}

ull solve(const string& s, int idx, ull k) {
    if (s[idx] == '0') {
        return string_to_val(s, idx);
    }

    ull lim = s[idx] - '0';
    ull ans = 0;
    if (idx > 0) { 
        if (idx == s.size() - 1) {
            ans = cnt[idx - 1];
        } else {
            ans = pw[idx - 1];
        }
    }
    else ans = 1;

    for (ull i = 1; i < lim; i++) {
        ull g = __gcd(k, i);
        ull rem = k / g;
        
        if (idx > 0) {
            ans += compute2(rem, idx - 1);
        } else {
            if (rem == 1) ans++;
        }

        ans %= mod;
    }

    {
        ull g = __gcd(lim, k);
        ull rem = k / g;

        if (idx > 0) {
            ans += solve(s, idx - 1, rem);
        } else {
            if (rem == 1) ans++;
        }
    }

    return ans % mod;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

    string l, r;
    cin >> k;
    cin >> l >> r;

    precomp();

    // for (int i = 0; i < 5; i++) {
    //     cout << cnt[i] << nl;
    // }

    __uint128_t L = 0;
    for (auto it : l) {
        L *= 10;
        L += it - '0';
    }
    L--;
    l = "";
    while (L != 0) {
        char c = L % 10 + '0';
        l += c;
        L /= 10;
    }

    if (l == "") l = "0";

    reverse(all(r));

    // cout << l << " " << r << nl;
    
    ull a = solve(r, r.size() - 1, k);
    ull b = solve(l, l.size() - 1, k);
    // cout << a << " " << b << nl;

    ull ans = (mod + a - b) % mod;
    
    cout << ans;
}

详细

Test #1:

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

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3564kb

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3688kb

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 100 100000

output:

99901

result:

ok single line: '99901'

Test #5:

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

input:

1 1 1

output:

1

result:

ok single line: '1'

Test #6:

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

input:

10 800 43021

output:

22679

result:

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