結果

問題 No.377 背景パターン
ユーザー maspymaspy
提出日時 2020-04-15 18:28:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,388 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 44,676 KB
最終ジャッジ日時 2024-04-09 18:55:53
合計ジャッジ時間 9,721 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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