結果

問題 No.1287 えぬけー
ユーザー kk
提出日時 2021-03-23 17:15:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 883 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 198,968 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-08-16 19:08:04
合計ジャッジ時間 7,023 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long M = 1e9 + 7;

long long totient(long long n) {
  long long ret = n;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ret = ret / i * (i - 1);
      while (n % i == 0)
        n /= i;
    }
  }
  if (n != 1) 
    ret = ret / n * (n - 1);
  return ret;
}

long long modpow(long long x, long long p, long long mod) {
  long long ret = 1;
  while (p) {
    if (p & 1)
      ret = ret * x % mod;
    x = x * x % mod;
    p >>= 1;
  }
  return ret;
}

// x = N^k (mod M)
long long solve() {
  long long x, k;
  cin >> x >> k;

  if (k == 1)
    return x;

  long long l = modpow(M-1, totient(k)-1, k) * (k-1) % k;
  return modpow(x, (l * (M - 1) + 1) / k, M);
}


int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int T;
  cin >> T;
  while (T--)
    cout << solve() << endl;

  return 0;
}
0