結果
| 問題 | No.377 背景パターン |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-09-21 12:56:26 |
| 言語 | C++14 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 266 ms / 5,000 ms |
| + 247µs | |
| コード長 | 2,362 bytes |
| 記録 | |
| コンパイル時間 | 1,280 ms |
| コンパイル使用メモリ | 193,396 KB |
| 実行使用メモリ | 9,904 KB |
| 最終ジャッジ日時 | 2026-09-21 12:56:30 |
| 合計ジャッジ時間 | 3,620 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pairi = pair<ll, ll>;
#define fi first
#define se second
const ll INF = 4e18;
const ll MOD = 1e9 + 7;
const ll base = 31;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll int_pow(ll a, ll base, ll mod = MOD) {
ll res = 1; a %= mod;
while (base) {
if (base & 1) res = res * a % mod;
a = a * a % mod; base >>= 1;
} return res;
}
ll inv(ll n) {
return int_pow(n, MOD - 2);
}
void solve() {
ll ans = 0;
ll h, w, k; cin >> h >> w >> k;
vector<ll> dh, dw;
for (ll i = 1; i * i <= h; i++) {
if (h % i == 0) {
dh.push_back(i);
if (i * i != h) dh.push_back(h / i);
}
}
for (ll i = 1; i * i <= w; i++) {
if (w % i == 0) {
dw.push_back(i);
if (i * i != w) dw.push_back(w / i);
}
}
sort(dh.rbegin(), dh.rend());
sort(dw.rbegin(), dw.rend());
ll nh = dh.size(), nw = dw.size();
vector<ll> gh(nh), gw(nw);
for (int i = 0; i < nh; i++) {
gh[i] = h / dh[i];
for (int j = 0; j < i; j++) {
if (dh[j] % dh[i] == 0) gh[i] -= gh[j];
}
}
for (int i = 0; i < nw; i++) {
gw[i] = w / dw[i];
for (int j = 0; j < i; j++) {
if (dw[j] % dw[i] == 0) gw[i] -= gw[j];
}
}
for (int i = 0; i < nh; i++) {
for (int j = 0; j < nw; j++) {
ll po = dh[i] * dw[j] % (MOD - 1) * __gcd(h / dh[i], w / dw[j]) % (MOD - 1);
ll ad = gh[i] * gw[j] % MOD * int_pow(k, po) % MOD;
ans = (ans + ad) % MOD;
}
}
ans = ans * inv(h * w) % MOD;
cout << ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cerr << "Program started.\n";
auto start = chrono::steady_clock::now();
string problem = "std";
if (fopen((problem + ".INP").c_str(), "r")) {
freopen((problem + ".INP").c_str(), "r", stdin);
freopen((problem + ".OUT").c_str(), "w", stdout);
}
int testcase = 1; //cin >> testcase;
while (testcase--) solve();
auto end = chrono::steady_clock::now();
cerr << "Program finished in " << chrono::duration_cast<chrono::milliseconds>(end - start).count() << " ms.";
}
vjudge1