結果
| 問題 |
No.2207 pCr検査
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-15 23:03:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,878 bytes |
| コンパイル時間 | 380 ms |
| コンパイル使用メモリ | 81,940 KB |
| 実行使用メモリ | 281,264 KB |
| 最終ジャッジ日時 | 2025-04-15 23:04:51 |
| 合計ジャッジ時間 | 6,064 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 29 |
ソースコード
def main():
import sys
from collections import defaultdict
k = int(sys.stdin.readline())
factors = {}
for _ in range(k):
p, e = map(int, sys.stdin.readline().split())
factors[p] = e
# Generate candidate p's (primes with exponent 1 in N)
candidates = [p for p in factors if factors[p] == 1]
# Check r=1 case: N must be a single prime with exponent 1
if len(factors) == 1 and factors.get(candidates[0], 0) == 1:
p = candidates[0]
print(p, 1)
return
# Check r=2 case: p(p-1) == 2N
# Compute 2N's factors
two_n_factors = defaultdict(int)
for p in factors:
two_n_factors[p] = factors[p]
two_n_factors[2] += 1 # multiply by 2
# For each candidate p, check if p is in two_n_factors with exponent 1
# and (two_n_factors without p) equals p-1's factors
for p in candidates:
if two_n_factors.get(p, 0) != 1:
continue
# Compute two_n / p's factors
tn_over_p = defaultdict(int, two_n_factors)
if tn_over_p[p] == 1:
del tn_over_p[p]
else:
tn_over_p[p] -= 1
# Compute p-1
p_minus_1 = p - 1
# Now check if the factors of p-1 match tn_over_p
# We need to factorize p_minus_1 and compare with tn_over_p
temp = p_minus_1
pm_factors = defaultdict(int)
for prime in tn_over_p:
if temp == 1:
break
while temp % prime == 0:
pm_factors[prime] += 1
temp //= prime
if temp != 1:
# p-1 has a prime factor not in tn_over_p
continue
# Check if pm_factors matches tn_over_p
if pm_factors == tn_over_p:
print(p, 2)
return
# If no solution found
print(-1, -1)
if __name__ == "__main__":
main()
lam6er