結果
問題 | No.377 背景パターン |
ユーザー | yosupot |
提出日時 | 2016-06-05 01:05:22 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 532 ms / 5,000 ms |
コード長 | 2,731 bytes |
コンパイル時間 | 1,031 ms |
コンパイル使用メモリ | 109,764 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-17 03:33:00 |
合計ジャッジ時間 | 2,773 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 5 ms
5,376 KB |
testcase_14 | AC | 5 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 508 ms
5,376 KB |
testcase_17 | AC | 532 ms
5,376 KB |
testcase_18 | AC | 3 ms
5,376 KB |
ソースコード
#include <iostream> #include <cstdio> #include <cassert> #include <cstring> #include <vector> #include <valarray> #include <array> #include <queue> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <algorithm> #include <cmath> #include <complex> #include <random> using namespace std; using ll = long long; using ull = unsigned long long; constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);} ll gcd(ll a, ll b) {return (b==0) ? a : gcd(b, a%b);} ll lcm(ll a, ll b) {return a/gcd(a, b)*b;} /// x^n template<class T> T pow(T x, ll n) { T r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template<uint MD> struct ModInt { uint v; ModInt() : v(0) {} ModInt(ll v) : v(normS(v%MD+MD)) {} uint value() const {return v;} static uint normS(const uint &x) {return (x<MD)?x:x-MD;}; static ModInt make(const uint &x) {ModInt m; m.v = x; return m;} const ModInt operator+(const ModInt &r) const {return make(normS(v+r.v));} const ModInt operator-(const ModInt &r) const {return make(normS(v+normS(MD-r.v)));} const ModInt operator*(const ModInt &r) const {return make((ull)v*r.v%MD);} ModInt& operator+=(const ModInt &r) {return *this=*this+r;} ModInt& operator-=(const ModInt &r) {return *this=*this-r;} ModInt& operator*=(const ModInt &r) {return *this=*this*r;} static ModInt inv(const ModInt &x) { return pow(ModInt(x), MD-2); } }; using Mint = ModInt<TEN(9)+7>; using P = pair<ll, ll>; vector<P> calc(ll X) { vector<ll> v; for (ll i = 1; i*i <= X; i++) { if (X%i == 0) { v.push_back(i); if (i*i != X) { v.push_back(X/i); } } } sort(v.begin(), v.end()); int N = (int)v.size(); vector<P> ans(N); for (int i = N-1; i >= 0; i--) { ll co = X/v[i]; for (int j = i+1; j < N; j++) { if (v[j] % v[i] == 0) { co -= ans[j].second; } } ans[i] = P(v[i], co); } return ans; } int main() { ll h, w, k; cin >> h >> w >> k; Mint ans = 0; vector<P> v1 = calc(h), v2 = calc(w); int N = (int)v1.size(), M = (int)v2.size(); /* printf("a\n"); for (auto d: v1) { printf("(%d %d)\n", d.first, d.second); } printf("b\n"); for (auto d: v2) { printf("(%d %d)\n", d.first, d.second); }*/ for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { ans += pow(Mint(k), h*w/lcm(h/v1[i].first, w/v2[j].first))*v1[i].second*v2[j].second; } } ans *= Mint::inv(h)*Mint::inv(w); cout << ans.value() << endl; return 0; }