結果

問題 No.1164 GCD Products hard
ユーザー kyo1kyo1
提出日時 2021-07-22 22:26:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 902 bytes
コンパイル時間 1,931 ms
コンパイル使用メモリ 199,964 KB
実行使用メモリ 42,416 KB
最終ジャッジ日時 2023-09-24 17:38:53
合計ジャッジ時間 46,009 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,804 ms
29,956 KB
testcase_01 AC 2,365 ms
32,928 KB
testcase_02 AC 1,603 ms
24,952 KB
testcase_03 AC 420 ms
10,428 KB
testcase_04 WA -
testcase_05 AC 1,914 ms
29,404 KB
testcase_06 AC 2,398 ms
35,128 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1,489 ms
26,136 KB
testcase_10 AC 440 ms
9,788 KB
testcase_11 AC 1,684 ms
27,696 KB
testcase_12 AC 2,473 ms
34,700 KB
testcase_13 AC 1,323 ms
21,924 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1,857 ms
28,580 KB
testcase_18 AC 1,531 ms
26,556 KB
testcase_19 WA -
testcase_20 AC 793 ms
15,580 KB
testcase_21 TLE -
testcase_22 AC 1 ms
4,380 KB
testcase_23 WA -
testcase_24 TLE -
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 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, prev = 0;
  vector<int> P(B + 1, 0);
  for (int g = B; g > 0; g--) {
    int x = B / g - (A - 1) / g;
    if (x == prev) {
      P[g] = P[g + 1];
    } else {
      P[g] = pow(x, N, MOD - 1);
    }
    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