結果

問題 No.1164 GCD Products hard
ユーザー kyo1kyo1
提出日時 2021-07-22 22:31:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,981 ms / 2,500 ms
コード長 881 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 200,776 KB
実行使用メモリ 42,268 KB
最終ジャッジ日時 2023-09-24 17:47:46
合計ジャッジ時間 28,733 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,229 ms
29,884 KB
testcase_01 AC 1,507 ms
32,764 KB
testcase_02 AC 894 ms
25,128 KB
testcase_03 AC 222 ms
10,416 KB
testcase_04 AC 158 ms
11,076 KB
testcase_05 AC 1,220 ms
29,468 KB
testcase_06 AC 1,366 ms
35,060 KB
testcase_07 AC 1,413 ms
36,664 KB
testcase_08 AC 1,404 ms
36,608 KB
testcase_09 AC 927 ms
26,120 KB
testcase_10 AC 200 ms
9,684 KB
testcase_11 AC 986 ms
27,636 KB
testcase_12 AC 1,458 ms
34,736 KB
testcase_13 AC 692 ms
22,004 KB
testcase_14 AC 610 ms
25,828 KB
testcase_15 AC 1,392 ms
37,236 KB
testcase_16 AC 772 ms
27,808 KB
testcase_17 AC 1,100 ms
28,612 KB
testcase_18 AC 986 ms
26,572 KB
testcase_19 AC 159 ms
11,496 KB
testcase_20 AC 384 ms
15,620 KB
testcase_21 AC 1,650 ms
37,320 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1,236 ms
42,268 KB
testcase_24 AC 1,981 ms
42,176 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const 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;
  int u = 0, v = 0;
  vector<int> P(B + 1, 0);
  for (int g = B; g > 0; g--) {
    int x = B / g - (A - 1) / g;
    P[g] = x == u ? v : pow(x, N, MOD - 1);
    u = x, v = P[g];
    for (int i = 2 * g; i < B + 1; i += g) {
      P[g] -= P[i];
      if (P[g] < 0) P[g] += MOD - 1;
    }
    res = static_cast<int64_t>(res) * pow(g, P[g], MOD) % MOD;
  }
  cout << res << '\n';
  return 0;
}
0