結果

問題 No.1164 GCD Products hard
ユーザー rlangevinrlangevin
提出日時 2023-09-10 17:28:59
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,421 bytes
コンパイル時間 5,604 ms
コンパイル使用メモリ 306,520 KB
実行使用メモリ 125,408 KB
最終ジャッジ日時 2023-09-10 17:29:45
合計ジャッジ時間 43,817 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,538 ms
85,720 KB
testcase_01 AC 1,993 ms
94,684 KB
testcase_02 AC 1,383 ms
71,408 KB
testcase_03 AC 403 ms
26,792 KB
testcase_04 AC 392 ms
28,172 KB
testcase_05 AC 1,652 ms
84,400 KB
testcase_06 AC 2,007 ms
103,592 KB
testcase_07 AC 1,993 ms
109,540 KB
testcase_08 AC 1,841 ms
108,680 KB
testcase_09 AC 1,314 ms
74,712 KB
testcase_10 AC 397 ms
24,212 KB
testcase_11 AC 1,471 ms
79,120 KB
testcase_12 AC 2,072 ms
103,524 KB
testcase_13 AC 1,155 ms
62,220 KB
testcase_14 AC 1,092 ms
73,708 KB
testcase_15 AC 2,047 ms
111,048 KB
testcase_16 AC 1,275 ms
79,976 KB
testcase_17 AC 1,650 ms
82,084 KB
testcase_18 AC 1,375 ms
75,596 KB
testcase_19 AC 436 ms
29,952 KB
testcase_20 AC 755 ms
41,900 KB
testcase_21 AC 2,256 ms
111,728 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1,987 ms
125,408 KB
testcase_24 TLE -
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 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;
    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;
    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 = 2 * p; j <= B; j += p){
            int n = j/p;
            dp[n] -= dp[j];
            dp[n] = (mod - 1 + dp[n]) % (mod - 1); 
        }
    }

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