結果

問題 No.1164 GCD Products hard
ユーザー 👑 Kazun
提出日時 2021-06-15 04:05:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,224 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 71,168 KB
実行使用メモリ 72,808 KB
最終ジャッジ日時 2024-12-25 18:12:51
合計ジャッジ時間 40,330 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

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