結果

問題 No.1164 GCD Products hard
ユーザー rlangevinrlangevin
提出日時 2023-09-10 19:33:02
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,423 bytes
コンパイル時間 6,366 ms
コンパイル使用メモリ 309,084 KB
実行使用メモリ 86,704 KB
最終ジャッジ日時 2023-09-10 19:33:51
合計ジャッジ時間 44,234 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,493 ms
58,716 KB
testcase_01 AC 2,018 ms
64,792 KB
testcase_02 AC 1,366 ms
49,372 KB
testcase_03 AC 398 ms
19,384 KB
testcase_04 AC 419 ms
20,128 KB
testcase_05 AC 1,631 ms
58,228 KB
testcase_06 AC 2,037 ms
72,712 KB
testcase_07 AC 2,003 ms
75,936 KB
testcase_08 AC 1,830 ms
76,160 KB
testcase_09 AC 1,284 ms
51,532 KB
testcase_10 AC 405 ms
17,376 KB
testcase_11 AC 1,450 ms
54,632 KB
testcase_12 AC 2,067 ms
72,532 KB
testcase_13 AC 1,149 ms
43,264 KB
testcase_14 AC 1,037 ms
50,796 KB
testcase_15 AC 2,053 ms
77,260 KB
testcase_16 AC 1,258 ms
55,432 KB
testcase_17 AC 1,624 ms
56,540 KB
testcase_18 AC 1,367 ms
52,084 KB
testcase_19 AC 465 ms
21,404 KB
testcase_20 AC 726 ms
29,200 KB
testcase_21 AC 2,276 ms
76,692 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2,046 ms
86,704 KB
testcase_24 TLE -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 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