結果

問題 No.2207 pCr検査
ユーザー gew1fw
提出日時 2025-06-12 14:43:53
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,138 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 269,572 KB
最終ジャッジ日時 2025-06-12 14:44:36
合計ジャッジ時間 5,571 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other TLE * 1 -- * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import sys

def compute_M(factors, p):
    M = 1
    for prime, exp in factors.items():
        if prime != p:
            M *= prime ** exp
    return M

def main():
    input = sys.stdin.read().split()
    idx = 0
    k = int(input[idx])
    idx += 1
    factors = {}
    for _ in range(k):
        p = int(input[idx])
        e = int(input[idx+1])
        factors[p] = e
        idx += 2

    candidates = [p for p in factors if factors[p] == 1]

    for p in candidates:
        try:
            M = compute_M(factors, p)
        except:
            continue
        max_r = min(10**5, p)
        for r in range(1, max_r + 1):
            k_val = r - 1
            if k_val > p - 1:
                break
            numerator = 1
            for i in range(k_val):
                term = p - 1 - i
                numerator *= term
            denominator = math.factorial(k_val)
            try:
                C = numerator // denominator
            except:
                continue
            if C == M * r:
                print(p, r)
                return
    print(-1, -1)

if __name__ == '__main__':
    main()
0