結果

問題 No.1164 GCD Products hard
ユーザー 👑 KazunKazun
提出日時 2021-06-15 04:05:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,224 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 70,808 KB
実行使用メモリ 36,212 KB
最終ジャッジ日時 2023-08-26 18:14:34
合計ジャッジ時間 6,849 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 486 ms
36,212 KB
testcase_01 AC 676 ms
35,056 KB
testcase_02 AC 480 ms
27,332 KB
testcase_03 AC 141 ms
11,600 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>

using namespace std;
using ll=long long;

vector<int> Sieve_of_Eratosthenes(int N){
    vector<int> T(N+1,1);
    T[0]=0; T[1]=0;
    
    for (int x=4; x<=N; x+=2) T[x]=0;
    for (int x=9; x<=N; x+=3) T[x]=0;

    int a=5,b,c;
    int Flag=0;
    while (a*a<=N){
        if (T[a]){
            b=a*a;
            c=2*a;
            while (b<=N){
                T[b]=0;
                b+=c;
            }
        }
        a+=2+2*Flag;
        Flag^=1;
    }

    vector<int> P;
    for (int x=0; x<=N; x++){
        if (T[x]) P.push_back(x);
    }
    return P;
}

ll pow_mod(ll a, ll k, ll mod){
    if (k==0) return 1;
    else if (k%2) return (a*pow_mod(a,k-1,mod))%mod;
    else{
        ll b=pow_mod(a,k/2,mod);
        return (b*b)%mod;
    }
}

int main(){
    int A,B,N;
    cin >> A >> B >> N;
    vector<int> P=Sieve_of_Eratosthenes(B);
    
    ll X=1, Mod=1e9+7,q,t,c;
    for (auto p:P){
        q=p; t=0;
        while (1){
            if (q>B) break;
            
            c=B/q-(A-1)/q;
            if (c==0) continue;
            t+=pow_mod(c,N,Mod-1); t%=Mod-1;
            q*=p;
        }
        X*=pow_mod(p,t,Mod); X%=Mod;
    }
    
    cout << X << endl;
}
0