QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611045#7954. Special Numbersrgnerdplayer#WA 0ms3836kbC++203.6kb2024-10-04 19:02:372024-10-04 19:02:37

Judging History

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

  • [2024-10-04 19:02:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3836kb
  • [2024-10-04 19:02:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using ll = long long;

#define SZ(v) (ll)((v).size())
#define pb emplace_back
#define AI(i) begin(i),end(i)
#define X first
#define Y second

constexpr int P = 1e9 + 7;
void inc(int &a, int b) {
    a += b;
    if (a >= P) {
        a -= P;
    }
}

mt19937 rng(58);

int main(){

    cin.tie(nullptr)->sync_with_stdio(false);
    
    auto solve = [&]() {
        i64 k;
        cin >> k;

        auto read = [&]() {
            string s;
            cin >> s;
            reverse(s.begin(), s.end());
            vector<int> a(s.size());
            for (int i = 0; i < s.size(); i++) {
                a[i] = s[i] - '0';
            }
            return a;
        };

        auto L = read();
        auto R = read();
        L[0]--;

        for (int i = 0; i < L.size(); i++) {
            if (L[i] < 0) {
                assert(i + 1 != L.size());
                L[i] += 10;
                L[i + 1]--;
            } else {
                break;
            }
        }

        while (L.size() > 1 && L.back() == 0) {
            L.pop_back();
        }

        vector<int> primes, pows;
        for (int p : {2, 3, 5, 7}) {
            if (k % p != 0) {
                continue;
            }
            primes.push_back(p);
            pows.push_back(0);
            while (k % p == 0) {
                k /= p;
                pows.back()++;
            }
        }

        if (k != 1) {
            cout << "0\n";
            return;
        }

        vector decomp(10, vector<int>(primes.size()));
        for (int i = 1; i < 10; i++) {
            int x = i;
            for (int j = 0; j < primes.size(); j++) {
                while (x % primes[j] == 0) {
                    decomp[i][j]++;
                    x /= primes[j];
                }
                decomp[i][j] = min(decomp[i][j], pows[j]);
            }
        }

        auto add = [&](vector<int> a, vector<int> b) {
            vector<int> c(primes.size());
            for (int i = 0; i < primes.size(); i++) {
                c[i] = min(pows[i], a[i] + b[i]);
            }
            return c;
        };

        auto work = [&](vector<int> R) {
            vector dp(2, map<vector<int>, int>()), ndp = dp;
            int ans = 0;
            for (int dig = R.size() - 1; dig >= 0; dig--) {
                ndp.assign(2, {});
                for (int x : {0, 1}) {
                    for (auto [a, c] : dp[x]) {
                        {
                            bool y = x && R[dig] == 0;
                            int add = c;
                            for (int i = 0; i < dig; i++) {
                                add = 1LL * add * (y ? R[i] + 1 : 10) % P;
                            }
                            inc(ans, add);
                        }
                        for (int i = 1; i <= (x ? R[dig] : 9); i++) {
                            if (decomp[i].empty()) {
                                continue;
                            }
                            inc(ndp[x && i == R[dig]][add(a, decomp[i])], c);
                        }
                    }
                }
                for (int i = 1; i <= (dig + 1 == R.size() ? R[dig] : 9); i++) {
                    inc(ndp[dig + 1 == R.size() && i == R[dig]][decomp[i]], 1);
                }
                swap(dp, ndp);
            }
            for (int x : {0, 1}) {
                inc(ans, dp[x][pows]);
            }
            return ans;
        };

        int cr = work(R), cl = work(L);
        int ans = (cr + P - cl) % P;
        cout << ans << '\n';
    };

    solve();
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 1 20

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5 50 100

output:

19

result:

ok single line: '19'

Test #3:

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

input:

15 11 19

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 100 100000

output:

9991

result:

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