結果
問題 | No.377 背景パターン |
ユーザー | 0w1 |
提出日時 | 2017-04-24 22:31:36 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,251 bytes |
コンパイル時間 | 371 ms |
コンパイル使用メモリ | 87,000 KB |
実行使用メモリ | 83,984 KB |
最終ジャッジ日時 | 2023-10-11 13:23:59 |
合計ジャッジ時間 | 7,277 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
77,272 KB |
testcase_01 | AC | 122 ms
77,388 KB |
testcase_02 | AC | 119 ms
77,496 KB |
testcase_03 | AC | 121 ms
77,512 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 108 ms
72,752 KB |
testcase_08 | AC | 110 ms
72,744 KB |
testcase_09 | AC | 110 ms
72,760 KB |
testcase_10 | AC | 109 ms
72,588 KB |
testcase_11 | AC | 110 ms
72,500 KB |
testcase_12 | AC | 109 ms
72,704 KB |
testcase_13 | AC | 201 ms
79,620 KB |
testcase_14 | AC | 173 ms
78,736 KB |
testcase_15 | AC | 118 ms
77,060 KB |
testcase_16 | AC | 1,903 ms
83,984 KB |
testcase_17 | AC | 1,923 ms
82,648 KB |
testcase_18 | AC | 120 ms
77,320 KB |
ソースコード
from functools import reduce MOD = int( 1e9 ) + 7 H, W, K = map( int, input().split() ) def gcd( a, b ): if b == 0: return a return gcd( b, a % b ) def is_prime( n ): return n > 1 and all( n % i for i in range( 2, int( n ** 0.5 ) + 1 ) ) def get_prime( n ): return [ i for i in range( 1, int( n ** 0.5 ) + 1 ) if n % i == 0 and is_prime( i ) ] + [ n // i for i in range( 1, int( n ** 0.5 ) ) if n % i == 0 and is_prime( n // i ) ] hp, wp = get_prime( H ), get_prime( W ) def phi( x, memo = {} ): if x in memo: return memo[ x ] if H % x == 0: res = x for p in hp: if p > x: break if x % p == 0: res = res // p * ( p - 1 ) memo[ x ] = res return res else: res = x for p in wp: if p > x: break if x % p == 0: res = res // p * ( p - 1 ) memo[ x ] = res return res def factors( n ): return [ i for i in range( 1, int( n ** 0.5 ) + 1 ) if n % i == 0 ] + [ n // i for i in range( 1, int( n ** 0.5 ) ) if n % i == 0 ] hf, wf = factors( H ), factors( W ) ans = 0 for a in hf: for b in wf: ans += pow( K, H // a * W // b * gcd( a, b ) % ( MOD - 1 ), MOD ) * phi( a ) * phi( b ) ans %= MOD ans = ans * pow( H * W, MOD - 2, MOD ) % MOD print( ans )