結果

問題 No.1287 えぬけー
ユーザー DriceDrice
提出日時 2020-11-13 22:11:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 32,468 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 03:01:01
合計ジャッジ時間 1,314 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 76 ms
4,380 KB
testcase_06 AC 74 ms
4,376 KB
testcase_07 AC 78 ms
4,376 KB
testcase_08 AC 71 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>

long long power(long long a,long long b,long long mod){
    long long res = 1;
    while(b!=0){
        if(b%2) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

void exgcd(long long a,long long b,long long& x,long long& y){
    if(b==0){
        x = 1;
        y = 0;
    }
    else{
        exgcd(b,a%b,x,y);
        long long t = x;
        x = y;
        y = t-(a/b)*x;
    }
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
    long long x,k;
    scanf("%lld%lld",&x,&k);
    long long mod = 1e9+7;
    long long mMod = mod-1;
    long long a,b;
    exgcd(k,mMod,a,b);
    a = a%mMod;
    if(a<0) a += mMod;
    //debug
    //printf("a = %lld\n",a);
    //printf("%lld\n",a*k%mMod);
    printf("%lld\n",power(x,a,mod));
}
    return 0;
}
0