結果
| 問題 |
No.377 背景パターン
|
| コンテスト | |
| ユーザー |
ayaoni
|
| 提出日時 | 2021-04-12 20:06:17 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 3,120 ms / 5,000 ms |
| コード長 | 1,420 bytes |
| コンパイル時間 | 1,242 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 77,632 KB |
| 最終ジャッジ日時 | 2024-06-28 16:26:03 |
| 合計ジャッジ時間 | 8,445 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 14 |
ソースコード
import sys
from collections import defaultdict
from math import gcd
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())
def divisor(n): # nの約数全列挙
res = []
for i in range(1,int(n**.5)+1):
if n % i == 0:
res.append(i)
if i != n//i:
res.append(n//i)
return res
def phi(n):
if n == 1:
return 1
res = n
for i in range(2,int(n**.5)+1):
if n % i == 0:
res -= res//i
while n % i == 0:
n //= i
if n == 1: # 時間短縮
break
else:
res -= res//n
return res
H,W,K = MI()
mod = 10**9+7
div_H = divisor(H)
div_W = divisor(W)
phis = defaultdict()
for h in div_H:
phis[h] = phi(h)
for w in div_W:
phis[w] = phi(w)
ans = 0
for h in div_H:
hh = H//h
a = phi(hh)
for w in div_W:
ww = W//w
b = phi(ww)
ans += a*b*pow(K,h*w*gcd(hh,ww),mod)
ans %= mod
ans *= pow(H*W,mod-2,mod)
ans %= mod
print(ans)
ayaoni