結果

問題 No.551 夏休みの思い出(2)
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-08-12 00:49:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 985 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 458,628 KB
最終ジャッジ日時 2024-04-17 18:02:44
合計ジャッジ時間 90,778 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2,289 ms
75,476 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 TLE -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 2,279 ms
75,912 KB
testcase_48 AC 2,342 ms
75,772 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(100):
    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

    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