結果

問題 No.1164 GCD Products hard
ユーザー rlangevinrlangevin
提出日時 2023-09-10 19:35:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,423 bytes
コンパイル時間 4,756 ms
コンパイル使用メモリ 262,468 KB
実行使用メモリ 87,108 KB
最終ジャッジ日時 2023-09-10 19:36:12
合計ジャッジ時間 45,658 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,607 ms
58,696 KB
testcase_01 AC 2,116 ms
64,772 KB
testcase_02 AC 1,447 ms
49,332 KB
testcase_03 AC 404 ms
19,208 KB
testcase_04 AC 441 ms
20,192 KB
testcase_05 AC 1,769 ms
58,000 KB
testcase_06 AC 2,132 ms
71,616 KB
testcase_07 AC 2,151 ms
74,688 KB
testcase_08 AC 1,958 ms
75,668 KB
testcase_09 AC 1,426 ms
51,428 KB
testcase_10 AC 411 ms
17,404 KB
testcase_11 AC 1,580 ms
54,812 KB
testcase_12 AC 2,164 ms
71,848 KB
testcase_13 AC 1,232 ms
43,276 KB
testcase_14 AC 1,177 ms
50,956 KB
testcase_15 AC 2,284 ms
76,444 KB
testcase_16 AC 1,439 ms
55,092 KB
testcase_17 AC 1,764 ms
56,384 KB
testcase_18 AC 1,477 ms
52,280 KB
testcase_19 AC 449 ms
21,344 KB
testcase_20 AC 772 ms
29,320 KB
testcase_21 AC 2,422 ms
77,148 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2,145 ms
86,508 KB
testcase_24 TLE -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<int, int>;
using mint = modint1000000007;
using mint2 = modint;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<int> Sieve(int n){
    vector<int> lst(n + 1, 1);
    int i = 2;
    while ((ll)i * i <= n){
        if (lst[i]){
            for (int j = 2 * i; j <= n; j += i){
                lst[j] = 0;
            }
        }
        i++;
    }
    vector<int> p;
    for (int i = 2; i <= n; i++){
        if (lst[i]){
            p.push_back(i);
        }
    }
    
    return p;
}

ll modpow(ll v, ll N, int mod){
    ll val = 1;
    ll now = v;
    while (N){
        if (N & 1){
            val *= now;
            val %= mod;
        }
        now = now * now;
        now %= mod;
        N >>= 1;
    }
    return val;
}

int main()
{
    int A, B, N;
    cin >> A >> B >> N;
    int mod = 1000000007;
    mint2::set_mod(mod - 1);
    vector<mint2> dp(B + 1);
    for (int i = 1; i <= B; i++){
        mint2 v = B/i - (A - 1)/i;
        dp[i] = v.pow(N);
    }

    vector<int> lst = Sieve(B + 1);
    for (int p : lst){
        for (int j = 2 * p; j <= B; j += p){
            int n = j/p;
            dp[n] -= dp[j];
        }
    }

    mint ans = 1;
    for (int i = 1; i <= B; i++){
        ans *= mint(i).pow((ll)dp[i].val());
    }
    cout << ans.val() << endl;
}
0