結果
問題 | No.1164 GCD Products hard |
ユーザー |
![]() |
提出日時 | 2021-07-22 22:26:35 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 902 bytes |
コンパイル時間 | 6,003 ms |
コンパイル使用メモリ | 254,856 KB |
最終ジャッジ日時 | 2025-01-23 07:01:25 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 WA * 8 TLE * 2 |
ソースコード
#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; }