結果

問題 No.1164 GCD Products hard
ユーザー kyo1kyo1
提出日時 2021-06-22 15:11:40
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,709 ms / 2,500 ms
コード長 941 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 200,456 KB
実行使用メモリ 42,204 KB
最終ジャッジ日時 2023-09-05 16:49:16
合計ジャッジ時間 23,741 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,017 ms
30,004 KB
testcase_01 AC 1,133 ms
32,972 KB
testcase_02 AC 656 ms
25,132 KB
testcase_03 AC 218 ms
10,564 KB
testcase_04 AC 146 ms
11,112 KB
testcase_05 AC 960 ms
29,488 KB
testcase_06 AC 1,160 ms
34,948 KB
testcase_07 AC 1,156 ms
36,536 KB
testcase_08 AC 1,227 ms
36,600 KB
testcase_09 AC 741 ms
26,104 KB
testcase_10 AC 181 ms
9,704 KB
testcase_11 AC 727 ms
27,624 KB
testcase_12 AC 1,245 ms
34,796 KB
testcase_13 AC 575 ms
22,052 KB
testcase_14 AC 544 ms
25,852 KB
testcase_15 AC 1,199 ms
37,312 KB
testcase_16 AC 550 ms
28,056 KB
testcase_17 AC 897 ms
28,708 KB
testcase_18 AC 765 ms
26,580 KB
testcase_19 AC 132 ms
11,600 KB
testcase_20 AC 344 ms
15,688 KB
testcase_21 AC 1,415 ms
37,404 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 946 ms
42,144 KB
testcase_24 AC 1,709 ms
42,204 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 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;
  int u = 0, v = 0;
  vector<int> X(B + 1, 0);
  for (int g = B; g > 0; g--) {
    int a = (A - 1) / g, b = B / g;
    if (u != b - a) {
      X[g] = pow(b - a, N, mod - 1);
      u = b - a;
      v = X[g];
    } else {
      X[g] = v;
    }
    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