結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,885 ms
85,616 KB
testcase_01 AC 2,219 ms
94,732 KB
testcase_02 AC 1,525 ms
71,544 KB
testcase_03 AC 517 ms
27,140 KB
testcase_04 AC 445 ms
28,140 KB
testcase_05 AC 1,861 ms
84,400 KB
testcase_06 AC 2,254 ms
103,144 KB
testcase_07 AC 2,266 ms
108,732 KB
testcase_08 AC 2,213 ms
109,004 KB
testcase_09 AC 1,555 ms
74,504 KB
testcase_10 AC 443 ms
24,088 KB
testcase_11 AC 1,685 ms
79,108 KB
testcase_12 AC 2,277 ms
103,388 KB
testcase_13 AC 1,303 ms
62,248 KB
testcase_14 AC 1,416 ms
73,976 KB
testcase_15 AC 2,283 ms
111,008 KB
testcase_16 AC 1,544 ms
80,072 KB
testcase_17 AC 1,808 ms
82,084 KB
testcase_18 AC 1,667 ms
75,548 KB
testcase_19 AC 522 ms
29,952 KB
testcase_20 AC 838 ms
41,896 KB
testcase_21 TLE -
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2,217 ms
126,028 KB
testcase_24 TLE -
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 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;
#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 = 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