結果

問題 No.551 夏休みの思い出(2)
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-08-12 01:05:25
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 987 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 453,136 KB
最終ジャッジ日時 2024-04-17 18:12:13
合計ジャッジ時間 93,217 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,554 ms
75,836 KB
testcase_01 AC 2,584 ms
75,580 KB
testcase_02 AC 2,516 ms
75,748 KB
testcase_03 AC 2,578 ms
77,392 KB
testcase_04 AC 2,560 ms
77,352 KB
testcase_05 AC 2,616 ms
77,460 KB
testcase_06 AC 2,610 ms
77,688 KB
testcase_07 AC 2,535 ms
75,748 KB
testcase_08 AC 2,520 ms
75,556 KB
testcase_09 AC 2,530 ms
75,692 KB
testcase_10 AC 2,562 ms
75,616 KB
testcase_11 AC 2,558 ms
75,848 KB
testcase_12 AC 2,572 ms
75,376 KB
testcase_13 AC 2,612 ms
75,772 KB
testcase_14 AC 2,637 ms
75,552 KB
testcase_15 AC 2,673 ms
75,680 KB
testcase_16 AC 2,644 ms
75,460 KB
testcase_17 AC 2,811 ms
95,664 KB
testcase_18 AC 2,764 ms
86,648 KB
testcase_19 AC 3,061 ms
129,692 KB
testcase_20 AC 2,769 ms
86,516 KB
testcase_21 AC 2,897 ms
95,584 KB
testcase_22 AC 2,716 ms
81,360 KB
testcase_23 AC 2,673 ms
78,408 KB
testcase_24 AC 2,853 ms
85,540 KB
testcase_25 AC 2,765 ms
95,620 KB
testcase_26 AC 2,979 ms
113,896 KB
testcase_27 AC 3,674 ms
147,512 KB
testcase_28 TLE -
testcase_29 AC 3,702 ms
265,388 KB
testcase_30 TLE -
testcase_31 AC 3,858 ms
395,464 KB
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 TLE -
testcase_38 TLE -
testcase_39 TLE -
testcase_40 TLE -
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 TLE -
testcase_45 TLE -
testcase_46 TLE -
testcase_47 AC 2,636 ms
75,520 KB
testcase_48 AC 2,595 ms
75,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

P,R=map(int,input().split())
from collections import defaultdict
Q=int(input())  
def modinv(X):
    return pow(X,P-2,P)

revR=modinv(R)
Right= defaultdict(int)
for i in range(200):
    Right[i] = pow(revR,i,P)
    
Left =defaultdict(int)
R100=pow(R,200,P)

for i in range(5*10**6):
    Left[pow(R100,i,P)] = i
    
def solve(a,b,c):
    T=(b**2-4*a*c)*modinv(4*a*a)%P
    S=b*modinv(2*a)%P
    # (X+S)**2 == T なるXを一つ見つける
    # R**u == T のuを見つける
    if T == 0:
        print((-S) %P)
        return
    order = -1
    for j in range(200):
        key= Right[j]*T%P
        if key in Left.keys():
            order = 200* Left[key] + j
            break
    
    order =order % (P - 1 )

    if order%2!=0:
        print(-1)
        return
    else:
        V= pow(R,order//2,P)
        mini,maxi=min((V-S)%P,(-V-S)%P),max((V-S)%P,(-V-S)%P)
        print(mini,maxi)
        return
    
for i in range(Q):
    a,b,c=map(int,input().split())
    solve(a,b,c)
0