結果

問題 No.2207 pCr検査
ユーザー dachengzdachengz
提出日時 2023-02-06 12:40:29
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,706 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 86,456 KB
実行使用メモリ 79,000 KB
最終ジャッジ日時 2023-09-18 00:29:48
合計ジャッジ時間 13,117 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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