結果

問題 No.377 背景パターン
ユーザー sugim48sugim48
提出日時 2016-06-07 16:14:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,453 ms / 5,000 ms
コード長 1,954 bytes
コンパイル時間 1,003 ms
コンパイル使用メモリ 98,356 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 05:43:18
合計ジャッジ時間 4,622 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 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 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 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 1,369 ms
5,376 KB
testcase_17 AC 1,453 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
// struct edge { int u, v; ll w; };

int INF = INT_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int pow_mod(ll x, ll n, int M) {
	ll ans = 1;
	for (; n; n>>=1) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
	}
	return ans;
}

int inv_mod(int x, int p) {
	return pow_mod(x, p - 2, p);
}

vector<i_i> f(int N) {
	vector<int> ds;
	for (int x = 1; x * x <= N; x++)
		if (N % x == 0) {
			ds.push_back(x);
			if (x * x != N) ds.push_back(N / x);
		}
	sort(ds.begin(), ds.end());
	int M = ds.size();
	vector<int> a(M);
	for (int i = 0; i < M; i++) {
		int d = ds[i];
		a[i] = d;
		vector<int> es;
		for (int x = 1; x * x <= d; x++)
			if (d % x == 0) {
				es.push_back(x);
				if (x * x != d) es.push_back(d / x);
			}
		for (int e: es)
			if (e != d) {
				int j = lower_bound(ds.begin(), ds.end(), e) - ds.begin();
				a[i] -= a[j];
			}
	}
	vector<i_i> ans(M);
	for (int i = 0; i < M; i++)
		ans[i]= i_i(ds[i], a[i]);
	return ans;
}

int main() {
	int H, W, K; cin >> H >> W >> K;
	vector<i_i> a = f(H), b = f(W);
	int sum = 0;
	for (i_i p: a) for (i_i q: b)
		sum = (sum + (ll)p.second * q.second % MOD * pow_mod(K, (ll)H * W / lcm(p.first, q.first), MOD)) % MOD;
	sum = (ll)sum * inv_mod((ll)H * W % MOD, MOD) % MOD;
	cout << sum << endl;
}
0