QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#781037#7954. Special NumbersNYCU_MyGO#Compile Error//Python33.9kb2024-11-25 14:33:402024-11-25 14:33:41

Judging History

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

  • [2024-11-25 14:33:41]
  • 评测
  • [2024-11-25 14:33:40]
  • 提交

answer

#ifndef MyGO
#define MyGO
#include MyGO __FILE__ MyGO

const int mod = 1'000'000'007;

void solve() {
    int K, K_tmp; cin >> K, K_tmp = K;
    string L, R; cin >> L >> R;

    int k2 = 0, k3 = 0, k5 = 0, k7 = 0;
    while (K_tmp % 2 == 0) K_tmp /= 2, ++k2;
    while (K_tmp % 3 == 0) K_tmp /= 3, ++k3;
    while (K_tmp % 5 == 0) K_tmp /= 5, ++k5;
    while (K_tmp % 7 == 0) K_tmp /= 7, ++k7;
    // if (K > 1) { cout << 0 << "\n"; return; }

    ///            0  1  2  3  4  5  6  7  8  9 ///
    vector<int> p2{0, 0, 1, 0, 2, 0, 1, 0, 3, 0};
    vector<int> p3{0, 0, 0, 1, 0, 0, 1, 0, 0, 2};
    vector<int> p5{0, 0, 0, 0, 0, 1, 0, 0, 0, 0};
    vector<int> p7{0, 0, 0, 0, 0, 0, 0, 1, 0, 0};

    map<tuple<int, int, int, int, int, bool, bool, bool>, int> dp;
    auto _calc = [&](const string &lim, int e2, int e3, int e5, int e7, int d, bool is_cap, bool is_zero, bool is_first, auto &&self) -> int {
        if (d == SZ(lim)) {
            if (K_tmp > 1) return is_zero;
            else           return (is_zero or (e2 == k2 and e3 == k3 and e5 == k5 and e7 == k7));
        }
        // debug(e2, e3, e5, e7, d, is_cap, is_zero, is_first);
        if (auto it = dp.find(make_tuple(e2, e3, e5, e7, d, is_cap, is_zero, is_first)); it != end(dp)) return it->second;
        int ans = 0;
        for (int v = 0; v <= (is_cap ? lim[d] - '0' : 9); ++v) {
            ans += self(
                lim,
                min(k2, e2 + p2[v]),
                min(k3, e3 + p3[v]),
                min(k5, e5 + p5[v]),
                min(k7, e7 + p7[v]),
                d + 1,
                is_cap and (v == lim[d] - '0'),
                is_zero or (not is_first and v == 0),
                is_first and (v == 0),
                self
            );
        }
        // debug(e2, e3, e5, e7, d, is_cap, is_zero, is_first, ans);
        return dp[make_tuple(e2, e3, e5, e7, d, is_cap, is_zero, is_first)] = ans % mod;
    };
    auto calc = [&](string lim) -> int {
        dp.clear();
        int tmp = _calc(lim, 0, 0, 0, 0, 0, true, false, true, _calc);
        // debug(lim, tmp);
        return tmp;
    };

    auto chk = [&](string x) -> int {
        int mul = 1;
        for (char c : x) mul = mul * (c - '0') % K;
        return (mul % K == 0);
    };

    int ans = (calc(R) - calc(L) + chk(L) + mod) % mod;
    cout << ans << "\n";

    // int ans2 = 0;
    // for (int i = stoll(L); i <= stoll(R); ++i) ans2 += chk(to_string(i));
    // ans2 %= mod;
    // assert(ans == ans2);
}

int32_t main() {
    fastIO();
    
    int t = 1;
    // cin >> t;
    while (t--) solve();
}

#else

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

using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
#define int i64
using pii = pair<int, int>;

#define ee emplace
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())

template <typename T>
ostream& operator << (ostream &os, const vector<T> &vec) {
    for (int i = 0; i < SZ(vec); ++i) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}

#ifdef local
#define fastIO() void()
#define debug(...) \
    fprintf(stderr, "\u001b[33m"), \
    fprintf(stderr, "Line %d: (%s) = ", __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), \
    fprintf(stderr, "\u001b[0m")
template <typename T> void _do(T &&_t) { cerr << _t << "\n"; }
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) { cerr << _t << ", ", _do(_u...); }
#else
#define fastIO() cin.tie(0)->sync_with_stdio(0)
#define debug(...) void()
#endif

template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }

#endif

详细

  File "answer.code", line 5
    const int mod = 1'000'000'007;
                             ^
SyntaxError: unterminated string literal (detected at line 5)