結果

問題 No.377 背景パターン
ユーザー ayaoniayaoni
提出日時 2021-04-12 20:06:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,238 ms / 5,000 ms
コード長 1,420 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 79,600 KB
最終ジャッジ日時 2023-09-11 01:55:13
合計ジャッジ時間 9,861 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
77,016 KB
testcase_01 AC 108 ms
77,288 KB
testcase_02 AC 107 ms
77,008 KB
testcase_03 AC 112 ms
77,072 KB
testcase_04 AC 97 ms
72,096 KB
testcase_05 AC 94 ms
71,964 KB
testcase_06 AC 95 ms
72,224 KB
testcase_07 AC 96 ms
71,964 KB
testcase_08 AC 97 ms
71,764 KB
testcase_09 AC 100 ms
72,212 KB
testcase_10 AC 98 ms
72,376 KB
testcase_11 AC 98 ms
72,092 KB
testcase_12 AC 96 ms
72,004 KB
testcase_13 AC 143 ms
78,356 KB
testcase_14 AC 138 ms
78,344 KB
testcase_15 AC 106 ms
76,868 KB
testcase_16 AC 3,179 ms
79,368 KB
testcase_17 AC 3,238 ms
79,600 KB
testcase_18 AC 106 ms
76,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0