結果
| 問題 |
No.2207 pCr検査
|
| コンテスト | |
| ユーザー |
dachengz
|
| 提出日時 | 2023-02-06 12:40:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,706 bytes |
| コンパイル時間 | 320 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 65,664 KB |
| 最終ジャッジ日時 | 2024-07-04 17:39:18 |
| 合計ジャッジ時間 | 8,234 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 30 |
ソースコード
from math import log, lgamma
def deg(n, p):
ret = 0
n //= p
while n:
ret += n
n //= p
return ret
def isqrt(n):
if n <= 0:
return 0
x = int((n ** 0.5) * (1 + 1e-14))
while True:
y = (x + n // x) // 2
if y >= x:
return x
x = y
def smf_sieve(N):
v = isqrt(N)
smf = list(range(N + 1))
for d in range(2, N + 1, 2):
smf[d] = 2
for p in range(3, v + 1, 2):
if smf[p] != p:
continue
for d in range(p * p, N + 1, 2 * p):
if smf[d] == d:
smf[d] = p
return smf
from os.path import expanduser
in_file_path = expanduser("~/test.txt")
pe = []
with open(in_file_path, 'r', encoding='utf8') as in_file:
k = int(in_file.readline())
print(k)
for _ in range(k):
pe.append([int(x) for x in in_file.readline().split()])
P = pe[-1][0]
P1 = P + 1
needlog = 0.0
for p, e in pe:
if e > deg(P, p):
print(-1, -1)
exit
needlog += log(p) * e
lgP = lgamma(P1)
lo1, hi1 = 1, P // 2
if lgP - lgamma(hi1) - lgamma(P1 - hi1) - needlog < -1e-6:
print(-1, -1)
exit
while hi1 - lo1 > 1:
md = lo1 + (hi1 - lo1) // 2
lgcomb = lgP - lgamma(md + 1) - lgamma(P1 - md)
if lgcomb - needlog < -1e-6:
lo1 = md
else:
hi1 = md
lo2, hi2 = 1, P // 2
while hi2 - lo2 > 1:
md = lo2 + (hi2 - lo2) // 2
lgcomb = lgP - lgamma(md + 1) - lgamma(P1 - md)
if lgcomb - needlog > 1e-6:
hi2 = md
else:
lo2 = md
for r in range(hi1, lo2 + 1):
if all(deg(P, p) - deg(r, p) - deg(P - r, p) == e for p, e in pe):
print(P, r)
exit
else:
print(-1, -1)
dachengz