結果
問題 | No.377 背景パターン |
ユーザー |
![]() |
提出日時 | 2024-09-15 20:18:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 744 ms / 5,000 ms |
コード長 | 1,669 bytes |
コンパイル時間 | 3,246 ms |
コンパイル使用メモリ | 259,376 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-15 20:18:24 |
合計ジャッジ時間 | 5,562 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/modint>using mint = atcoder::modint1000000007;struct Divisor_n {std::vector<std::pair<int, int>> prime_factor;int pow(int n, int k) {int res = 1;while (k--)res *= n;return res;}public:Divisor_n(int n) {for (int i = 2; i * i <= n; i++) {if (n % i)continue;prime_factor.emplace_back(i, 0);while (n % i == 0) {prime_factor.back().second++;n /= i;}}if (n > 1)prime_factor.emplace_back(n, 1);}std::vector<int> divisors() {int prod = 1;for (const auto &[p, e] : prime_factor)prod *= e + 1;std::vector<int> res;for (int S : std::views::iota(0, prod)) {int x = 1;for (const auto &[p, e] : prime_factor) {x *= pow(p, S % (e + 1));S /= e + 1;}res.push_back(x);}return res;}int phi(int d) {int res = d;for (const int p : prime_factor | std::views::elements<0>)if (d % p == 0)(res /= p) *= p - 1;return res;}};using ll = long long;int main() {int h, w, k;std::cin >> h >> w >> k;Divisor_n H(h), W(w);mint ans = 0;for (int x : H.divisors())for (int y : W.divisors())ans += mint::raw(k).pow(h * ll(w) / std::lcm<ll, ll>(x, y)) *H.phi(x) * W.phi(y);std::cout << (ans / (h * mint::raw(w))).val() << std::endl;}