結果

問題 No.377 背景パターン
ユーザー cielciel
提出日時 2016-06-05 21:54:02
言語 PyPy3
(7.3.15)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 843 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,296 KB
実行使用メモリ 84,684 KB
最終ジャッジ日時 2023-08-29 01:41:08
合計ジャッジ時間 6,067 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from fractions import gcd
import sys,subprocess
if sys.version_info[0]>=3:
	raw_input=input
	xrange=range

def prime_division(n):
	h=defaultdict(int)
	line=subprocess.check_output(['factor',str(n)])
	for e in line.split()[1:]: h[int(e)]+=1
	return [(k,v) for k,v in h.items()]

def divisor_totient(a,d,n,t):
	if d==len(a):
		yield (n,t)
	else:
		for i in xrange(a[d][1]+1):
			for x,xt in divisor_totient(
				a,d+1,
				n*a[d][0]**i,
				(t if i==0 else t*(a[d][0]-1)*a[d][0]**(i-1))
			): yield (x,xt)

cache={}
M=1000000007
H,W,K=map(int,raw_input().split())
A=prime_division(H)
B=prime_division(W)
r=0
for a,at in divisor_totient(A,0,1,1):
	for b,bt in divisor_totient(B,0,1,1):
		key=W*H*gcd(a,b)//a//b
		if key not in cache: cache[key]=pow(K,key,M)
		r=(r+at*bt*cache[key])%M
print(r*pow(W*H,M-2,M)%M)
0