結果
| 問題 | 
                            No.377 背景パターン
                             | 
                    
| コンテスト | |
| ユーザー | 
                             maspy
                         | 
                    
| 提出日時 | 2020-04-15 18:28:09 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,388 bytes | 
| コンパイル時間 | 209 ms | 
| コンパイル使用メモリ | 13,056 KB | 
| 実行使用メモリ | 44,676 KB | 
| 最終ジャッジ日時 | 2024-10-01 18:58:20 | 
| 合計ジャッジ時間 | 11,930 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | RE * 5 | 
| other | RE * 14 | 
ソースコード
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
MOD = 10 ** 9 + 7
U = int(10 ** 4.5 + 10)
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
    if p * p >= U:
        break
    if is_prime[p]:
        is_prime[p * p:: p + p] = 0
primes = np.where(is_prime)[0]
def factor(N):
    div_p = primes[N % primes == 0].tolist()
    for p in div_p:
        e = 0
        while N % p == 0:
            N //= p
            e += 1
        yield (p, e)
    if N > 1:
        yield (N, 1)
def divisor_and_phi(N):
    div = np.array([1], np.int64)
    phi = np.array([1], np.int64)
    for p, e in factor(N):
        div = np.concatenate([div * pow(p, k) for k in range(0, e + 1)])
        phi = np.concatenate([phi] + [phi * (p - 1) * pow(p, k - 1) for k in range(1, e + 1)])
    return div, phi
H, W, K = map(int, read().split())
period_H, cnt_H = divisor_and_phi(H)
period_W, cnt_W = divisor_and_phi(W)
period = np.lcm.outer(period_H, period_W).ravel()
cnt = np.multiply.outer(cnt_H, cnt_W).ravel()
n_orbit = H * W // period
power = np.ones(len(n_orbit), np.int64)
KK = K
for i in range(64):
    power *= KK ** ((n_orbit >> i) & 1)
    power %= MOD
    KK *= KK
    KK %= MOD
x = (power * cnt % MOD).sum() % MOD
x *= pow(H * W, MOD - 2, MOD)
x %= MOD
print(x)
            
            
            
        
            
maspy