結果

問題 No.551 夏休みの思い出(2)
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-08-12 13:50:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,837 ms / 4,000 ms
コード長 996 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 119,800 KB
最終ジャッジ日時 2024-04-18 00:27:46
合計ジャッジ時間 25,542 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
64,640 KB
testcase_01 AC 171 ms
65,536 KB
testcase_02 AC 179 ms
67,072 KB
testcase_03 AC 243 ms
76,928 KB
testcase_04 AC 247 ms
77,568 KB
testcase_05 AC 266 ms
77,808 KB
testcase_06 AC 272 ms
78,080 KB
testcase_07 AC 166 ms
65,536 KB
testcase_08 AC 171 ms
65,792 KB
testcase_09 AC 171 ms
65,792 KB
testcase_10 AC 171 ms
66,048 KB
testcase_11 AC 173 ms
66,304 KB
testcase_12 AC 170 ms
66,028 KB
testcase_13 AC 171 ms
65,792 KB
testcase_14 AC 169 ms
65,664 KB
testcase_15 AC 172 ms
66,432 KB
testcase_16 AC 171 ms
65,664 KB
testcase_17 AC 198 ms
84,992 KB
testcase_18 AC 185 ms
77,312 KB
testcase_19 AC 225 ms
105,728 KB
testcase_20 AC 189 ms
77,056 KB
testcase_21 AC 188 ms
71,040 KB
testcase_22 AC 181 ms
72,064 KB
testcase_23 AC 176 ms
67,072 KB
testcase_24 AC 182 ms
76,032 KB
testcase_25 AC 193 ms
84,864 KB
testcase_26 AC 216 ms
102,016 KB
testcase_27 AC 516 ms
119,552 KB
testcase_28 AC 518 ms
119,800 KB
testcase_29 AC 416 ms
119,540 KB
testcase_30 AC 552 ms
119,424 KB
testcase_31 AC 459 ms
119,296 KB
testcase_32 AC 515 ms
119,560 KB
testcase_33 AC 596 ms
119,424 KB
testcase_34 AC 577 ms
119,296 KB
testcase_35 AC 403 ms
119,520 KB
testcase_36 AC 454 ms
119,296 KB
testcase_37 AC 1,837 ms
119,648 KB
testcase_38 AC 1,592 ms
119,560 KB
testcase_39 AC 581 ms
119,756 KB
testcase_40 AC 1,153 ms
119,424 KB
testcase_41 AC 757 ms
119,680 KB
testcase_42 AC 1,683 ms
119,424 KB
testcase_43 AC 1,626 ms
119,596 KB
testcase_44 AC 844 ms
119,692 KB
testcase_45 AC 801 ms
119,424 KB
testcase_46 AC 1,752 ms
119,424 KB
testcase_47 AC 169 ms
64,768 KB
testcase_48 AC 167 ms
64,256 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(4000):
    Right[i] = pow(revR,i,P)
    
Left =defaultdict(int)
R100=pow(R,4000,P)

for i in range(25*10**4):
    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(25*10**4):
        key= Right[j]*T%P
        if key in Left.keys():
            order = 4000* 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