結果

問題 No.1164 GCD Products hard
ユーザー kyo1kyo1
提出日時 2021-06-22 15:03:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,230 ms / 2,500 ms
コード長 966 bytes
コンパイル時間 3,800 ms
コンパイル使用メモリ 205,460 KB
実行使用メモリ 42,532 KB
最終ジャッジ日時 2023-09-05 16:41:27
合計ジャッジ時間 35,410 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,428 ms
30,016 KB
testcase_01 AC 1,614 ms
33,100 KB
testcase_02 AC 1,071 ms
25,468 KB
testcase_03 AC 274 ms
10,700 KB
testcase_04 AC 215 ms
10,996 KB
testcase_05 AC 1,400 ms
29,740 KB
testcase_06 AC 1,596 ms
35,012 KB
testcase_07 AC 1,637 ms
36,800 KB
testcase_08 AC 1,657 ms
36,800 KB
testcase_09 AC 1,144 ms
26,276 KB
testcase_10 AC 243 ms
10,168 KB
testcase_11 AC 1,160 ms
27,852 KB
testcase_12 AC 1,751 ms
34,828 KB
testcase_13 AC 941 ms
22,232 KB
testcase_14 AC 876 ms
25,832 KB
testcase_15 AC 1,690 ms
37,520 KB
testcase_16 AC 1,046 ms
28,164 KB
testcase_17 AC 1,364 ms
28,888 KB
testcase_18 AC 1,219 ms
26,900 KB
testcase_19 AC 228 ms
11,816 KB
testcase_20 AC 518 ms
15,900 KB
testcase_21 AC 1,934 ms
37,632 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1,575 ms
42,216 KB
testcase_24 AC 2,230 ms
42,532 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

constexpr int mod = 1000000007;

template <typename T>
int pow(int x, T n, int mod = std::numeric_limits<int>::max()) {
  int res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<int64_t>(res) * static_cast<int64_t>(x) % mod;
    x = static_cast<int64_t>(x) * static_cast<int64_t>(x) % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B, N;
  cin >> A >> B >> N;
  int res = 1;
  unordered_map<int, int> mp;
  vector<int> X(B + 1, 0);
  for (int g = B; g > 0; g--) {
    int a = (A - 1) / g, b = B / g;
    if (mp.find(b - a) == mp.end()) {
      X[g] = pow(b - a, N, mod - 1);
      mp[b - a] = X[g];
    } else {
      X[g] = mp[b - a];
    }
    for (int i = 2 * g; i < B + 1; i += g) {
      X[g] -= X[i];
      if (X[g] < 0) X[g] += mod - 1;
    }
    res = INT64_C(1) * res * pow(g, X[g], mod) % mod;
  }
  cout << res << '\n';
  return 0;
}
0