結果

問題 No.1164 GCD Products hard
ユーザー bokusunnybokusunny
提出日時 2023-04-15 10:05:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,001 bytes
コンパイル時間 2,331 ms
コンパイル使用メモリ 204,332 KB
実行使用メモリ 160,944 KB
最終ジャッジ日時 2024-04-19 05:57:02
合計ジャッジ時間 48,728 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,927 ms
111,232 KB
testcase_01 AC 2,439 ms
123,472 KB
testcase_02 AC 1,666 ms
92,216 KB
testcase_03 AC 436 ms
33,664 KB
testcase_04 AC 453 ms
35,392 KB
testcase_05 AC 2,028 ms
109,856 KB
testcase_06 AC 2,457 ms
131,908 KB
testcase_07 AC 2,492 ms
139,248 KB
testcase_08 AC 2,343 ms
138,552 KB
testcase_09 AC 1,606 ms
96,436 KB
testcase_10 AC 428 ms
30,564 KB
testcase_11 AC 1,818 ms
102,656 KB
testcase_12 AC 2,491 ms
131,000 KB
testcase_13 AC 1,371 ms
79,940 KB
testcase_14 AC 1,371 ms
95,332 KB
testcase_15 AC 2,433 ms
141,448 KB
testcase_16 AC 1,645 ms
103,892 KB
testcase_17 AC 1,971 ms
106,648 KB
testcase_18 AC 1,698 ms
97,832 KB
testcase_19 AC 491 ms
37,856 KB
testcase_20 AC 877 ms
54,016 KB
testcase_21 TLE -
testcase_22 AC 2 ms
6,940 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,948 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <atcoder/modint>
using namespace atcoder;

struct Eratosthenes {
   private:
    int _n;
    vector<bool> IsPrime;
    vector<int> MinFactor;
    vector<int> Mobius;

   public:
    Eratosthenes(int n = 1 << 20) : _n(n), IsPrime(n + 1, true), MinFactor(n + 1, -1), Mobius(n + 1, 1) {
        IsPrime[0] = IsPrime[1] = false;
        for (int p = 2; p <= n; p++) {
            if (!IsPrime[p]) continue;
            MinFactor[p] = p;
            Mobius[p] = -1;

            for (int q = 2 * p; q <= n; q += p) {
                IsPrime[q] = false;
                if (MinFactor[q] == -1) MinFactor[q] = p;
                if (q / p % p == 0) {
                    Mobius[q] = 0;
                } else {
                    Mobius[q] = -Mobius[q];
                }
            }
        }
    }

    bool is_prime(int x) { return IsPrime[x]; }

    vector<int> primes() {
        vector<int> res;
        for (int i = 2; i <= _n; i++) {
            if (IsPrime[i]) res.push_back(i);
        }
        return res;
    }

    vector<pair<int, int>> factorize(int n) {
        assert(1 <= n && n <= _n);

        vector<pair<int, int>> res;
        if (n == 1) return res;

        while (n > 1) {
            auto p = MinFactor[n];
            int ex = 0;
            while (MinFactor[n] == p) {
                ex++;
                n /= p;
            }
            res.emplace_back(p, ex);
        }

        return res;
    }

    vector<int> divisors(int n) {
        assert(1 <= n && n <= _n);

        vector<int> res = {1};
        if (n == 1) return res;

        auto pf = factorize(n);
        for (auto [p, ex] : pf) {
            int sz = (int)res.size();
            for (int i = 0; i < sz; i++) {
                int v = 1;
                for (int j = 0; j < ex; j++) {
                    v *= p;
                    res.push_back(res[i] * v);
                }
            }
        }

        return res;
    }

    vector<int> get_mobius() { return Mobius; }
};

long long modpow(long long a, long long n, int mod = 1000000007) {
    assert(mod != 0);
    if (mod == 1) return 0LL;
    a %= mod;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    int A, B, N;
    cin >> A >> B >> N;

    const int MOD = 1e9 + 7;

    Eratosthenes E(B + 1);
    vector<long long> F(B + 1);
    for (int g = 1; g <= B; g++) {
        F[g] = modpow(B / g - (A - 1) / g, N, MOD - 1);
    }
    for (int p = 2; p <= B; p++) {
        if (!E.is_prime(p)) continue;

        for (int k = 1; k * p <= B; k++) {
            F[k] -= F[k * p];
            F[k] += MOD - 1;
            if (F[k] >= MOD - 1) {
                F[k] -= MOD - 1;
            }
        }
    }

    long long ans = 1;
    for (int g = 1; g <= B; g++) {
        ans *= modpow(g, F[g], MOD);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}
0