結果
| 問題 | No.1164 GCD Products hard | 
| ユーザー |  kyo1 | 
| 提出日時 | 2021-06-22 15:11:40 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,925 ms / 2,500 ms | 
| コード長 | 941 bytes | 
| コンパイル時間 | 2,180 ms | 
| コンパイル使用メモリ | 193,220 KB | 
| 最終ジャッジ日時 | 2025-01-22 11:34:28 | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 27 | 
ソースコード
#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;
}
            
            
            
        