結果

問題 No.377 背景パターン
ユーザー convexineqconvexineq
提出日時 2020-03-05 21:12:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,558 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 18,080 KB
最終ジャッジ日時 2024-04-22 03:16:47
合計ジャッジ時間 7,594 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
11,008 KB
testcase_01 AC 40 ms
10,880 KB
testcase_02 AC 38 ms
10,880 KB
testcase_03 AC 42 ms
10,880 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 31 ms
10,880 KB
testcase_06 AC 32 ms
10,880 KB
testcase_07 AC 32 ms
10,880 KB
testcase_08 AC 32 ms
10,880 KB
testcase_09 AC 32 ms
11,136 KB
testcase_10 AC 32 ms
11,008 KB
testcase_11 AC 32 ms
10,880 KB
testcase_12 AC 32 ms
11,008 KB
testcase_13 AC 95 ms
10,880 KB
testcase_14 AC 64 ms
11,008 KB
testcase_15 AC 35 ms
10,880 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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