結果

問題 No.1164 GCD Products hard
ユーザー kk
提出日時 2020-08-15 07:40:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 216 ms / 2,500 ms
コード長 1,081 bytes
コンパイル時間 2,069 ms
コンパイル使用メモリ 197,296 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 23:40:47
合計ジャッジ時間 6,446 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
5,248 KB
testcase_01 AC 180 ms
5,376 KB
testcase_02 AC 128 ms
5,376 KB
testcase_03 AC 45 ms
5,376 KB
testcase_04 AC 44 ms
5,376 KB
testcase_05 AC 145 ms
5,376 KB
testcase_06 AC 173 ms
5,376 KB
testcase_07 AC 180 ms
5,376 KB
testcase_08 AC 172 ms
5,376 KB
testcase_09 AC 120 ms
5,376 KB
testcase_10 AC 41 ms
5,376 KB
testcase_11 AC 140 ms
5,376 KB
testcase_12 AC 179 ms
5,376 KB
testcase_13 AC 112 ms
5,376 KB
testcase_14 AC 106 ms
5,376 KB
testcase_15 AC 185 ms
5,376 KB
testcase_16 AC 125 ms
5,376 KB
testcase_17 AC 148 ms
5,376 KB
testcase_18 AC 132 ms
5,376 KB
testcase_19 AC 48 ms
5,376 KB
testcase_20 AC 74 ms
5,376 KB
testcase_21 AC 201 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 179 ms
5,376 KB
testcase_24 AC 216 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

const long long MOD = 1e9 + 7;

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;
}

vector<bool> psieve(int n) {
  vector<bool> pr(n);
  for (int i = 2; i < n; i++)
    pr[i] = true;
  for (int i = 2; i * i < n; i++) {
    if (!pr[i]) continue;
    for (int j = i * i; j < n; j += i)
      pr[j] = false;
  }
  return pr;
}

long long solve(long long a, long long b, long long n) {
  long long ret = 1;

  vector<bool> pr = psieve(b + 1);
  for (int x = 1; x <= b; x++) {
    if (!pr[x]) continue;
    long long y = x;
    while (y <= b) {
      long long tmp = modpow(b/y - (a-1)/y, n, MOD-1);
      ret *= modpow(x, tmp, MOD);
      ret %= MOD;
      y *= x;
    }
  }
  
  return ret;
}

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

  long long a, b, n;
  cin >> a >> b >> n;
  cout << solve(a, b, n) << endl;
  
  return 0;
}
0