結果

問題 No.377 背景パターン
ユーザー convexineqconvexineq
提出日時 2020-03-05 21:14:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,777 ms / 5,000 ms
コード長 1,558 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 82,912 KB
実行使用メモリ 67,456 KB
最終ジャッジ日時 2024-04-22 03:16:54
合計ジャッジ時間 5,178 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
58,496 KB
testcase_01 AC 45 ms
58,112 KB
testcase_02 AC 45 ms
58,368 KB
testcase_03 AC 48 ms
58,240 KB
testcase_04 AC 39 ms
51,840 KB
testcase_05 AC 38 ms
51,968 KB
testcase_06 AC 38 ms
52,608 KB
testcase_07 AC 39 ms
52,096 KB
testcase_08 AC 42 ms
52,736 KB
testcase_09 AC 39 ms
52,864 KB
testcase_10 AC 40 ms
52,480 KB
testcase_11 AC 40 ms
52,480 KB
testcase_12 AC 39 ms
52,480 KB
testcase_13 AC 58 ms
60,416 KB
testcase_14 AC 58 ms
60,416 KB
testcase_15 AC 42 ms
58,368 KB
testcase_16 AC 1,708 ms
67,456 KB
testcase_17 AC 1,777 ms
66,304 KB
testcase_18 AC 43 ms
58,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def divisor_list(N): #約数のリスト
    if N == 1: return [1]
    res = []
    for i in range(1,N):
        if i*i >= N: break
        if N%i == 0:
            res.append(i)
            res.append(N//i)
    if i*i == N: res.append(i)
    return sorted(res)

def prime_factors(N): #素因数のリスト
    factors = []
    if N&1==0:
        factors = [2]
        while N%2 == 0: N //= 2
    else: factorization = []
    M = int(N**0.5)+1
    for i in range(3,M,2):
        if N%i==0:
            while N%i == 0: N //= i
            factors.append(i)
    if N!= 1: factors.append(N)
    assert N != 0, "zero"
    return factors

# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

h,w,k = [int(i) for i in read().split()]

"""
Polya
(i,j) in Z/(h)*Z/(w)  の周期は lcm(h//gcd(i,h),w//gcd(j,w)) なので、
自由度は
d := h*w//lcm(h//gcd(i,h),w//gcd(j,w)) = gcd(i,h)*gcd(j,w)*gcd(h//gcd(i,h),w//gcd(j,w))
gcd(i,h) = a なる i は phi(h//a) 個ある
"""

hdiv = divisor_list(h)
wdiv = divisor_list(w)

div = list(set(hdiv+wdiv))
primes = list(set(prime_factors(h)+prime_factors(w)))
totient = {i:i for i in div}

for x in div:
    for p in primes:
        if x%p==0: totient[x] = totient[x]//p*(p-1)

ans = 0
hw = h*w
MOD = 10**9+7
from math import gcd
# ここでは、aa = h//a, bb = w//b のつもり
for aa in hdiv:
    for bb in wdiv:
        d = hw//(aa*bb)*gcd(aa,bb)
        ans += totient[aa]*totient[bb]%MOD*pow(k,d,MOD)%MOD

print(ans*pow(hw,MOD-2,MOD)%MOD)
0