結果

問題 No.1164 GCD Products hard
ユーザー rlangevinrlangevin
提出日時 2023-09-10 17:24:24
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,389 bytes
コンパイル時間 7,091 ms
コンパイル使用メモリ 305,548 KB
実行使用メモリ 124,860 KB
最終ジャッジ日時 2023-09-10 17:25:20
合計ジャッジ時間 48,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,914 ms
85,560 KB
testcase_01 AC 2,205 ms
94,752 KB
testcase_02 AC 1,530 ms
71,384 KB
testcase_03 AC 510 ms
26,764 KB
testcase_04 AC 448 ms
28,344 KB
testcase_05 AC 1,887 ms
84,616 KB
testcase_06 AC 2,225 ms
103,828 KB
testcase_07 AC 2,315 ms
109,020 KB
testcase_08 AC 2,259 ms
108,712 KB
testcase_09 AC 1,585 ms
74,584 KB
testcase_10 AC 442 ms
24,440 KB
testcase_11 AC 1,705 ms
79,072 KB
testcase_12 AC 2,293 ms
102,492 KB
testcase_13 AC 1,324 ms
62,248 KB
testcase_14 AC 1,335 ms
73,632 KB
testcase_15 AC 2,301 ms
110,696 KB
testcase_16 AC 1,526 ms
80,064 KB
testcase_17 AC 1,844 ms
82,400 KB
testcase_18 AC 1,698 ms
75,604 KB
testcase_19 AC 521 ms
29,856 KB
testcase_20 AC 830 ms
41,948 KB
testcase_21 TLE -
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2,275 ms
124,860 KB
testcase_24 TLE -
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 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;
#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;
    rep(i, 30){
        if ((N >> i) & 1){
            val *= now;
            val %= mod;
        }
        now = now * now;
        now %= mod;
    }
    return val;
}

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

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

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