結果

問題 No.550 夏休みの思い出(1)
ユーザー convexineq
提出日時 2021-02-26 01:18:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 60,416 KB
最終ジャッジ日時 2024-10-01 16:55:00
合計ジャッジ時間 5,256 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

def inv_gcd(x,y):
    if y==0: return 1,0
    r0,r1,s0,s1 = x,y,1,0
    while r1 != 0:
        a,b = divmod(r0,r1)
        r0, r1, s0, s1 = r1, b, s1, s0-a*s1
    return s0%y,r0 # s0*x + ??*y = r0 = gcd(x,y)

def Chinese_remainder_theorem(r,m):
    assert len(r)==len(m)
    r0, M0 = 0,1
    for r1, M1 in zip(r,m):
        if M0 < M1:
            r0,r1 = r1,r0
            M0,M1 = M1,M0
        minv,g = inv_gcd(M0,M1)
        Q,R = divmod(r1-r0,g)
        if R%g: return (0,0)
        M11 = M1//g
        r0 += Q%M11*minv%M11*M0
        M0 *= M11
    return r0,M0

def f(x): return ((x+a)*x+b)*x+c
def g(x): return (((x+a)%p*x+b)%p*x+c)%p

a,b,c = map(int,input().split())
res = []
primes = [100003, 100019, 100043]
for p in primes:
    r = []
    for i in range(p):
        if g(i) == 0: r.append(i)
    res.append(r)

from itertools import product
ans = []
P = 100003*100019*100043
for lst in product(*res):
    x = Chinese_remainder_theorem(lst,primes)[0]
    if f(x) == 0: ans.append(x)
    if f(x-P) == 0: ans.append(x-P)
ans.sort()
print(*ans)
0