結果

問題 No.1287 えぬけー
ユーザー tnakao0123tnakao0123
提出日時 2020-11-14 17:41:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 803 ms
コンパイル使用メモリ 91,436 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 05:14:15
合計ジャッジ時間 2,076 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1287.cc:  No.1287 えぬけー - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MOD = 1000000007;
const int PHM = (2 - 1) * (500000003 - 1);

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

int powmod(int a, int n, int mod) {  // a^n % mod
  int pm = 1;
  while (n > 0) {
    if (n & 1) pm = (ll)pm * a % mod;
    a = (ll)a * a % mod;
    n >>= 1;
  }
  return pm;
}

/* main */

int main() {
  // x=n^k,  n^{p-1}=1
  // let k*m=1(mod p-1) -> x^m=(n^k)^m=n^(k*m)=n
  // -> m=1/k(mod p-1)=k^phi(p-1)(mod p-1)
  
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int x, k;
    scanf("%d%d", &x, &k);

    int m = powmod(k, PHM - 1, MOD - 1);
    int n = powmod(x, m, MOD);

    printf("%d\n", n);
    //printf("x=%d, k=%d, m=%d -> k*m=%lld\n", x, k, m, (ll)k * m % (MOD - 1));
  }
  return 0;
}
0