結果

問題 No.551 夏休みの思い出(2)
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-08-12 01:08:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,551 ms / 4,000 ms
コード長 987 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 265,236 KB
最終ジャッジ日時 2024-04-17 18:13:52
合計ジャッジ時間 83,387 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,075 ms
75,648 KB
testcase_01 AC 1,078 ms
75,520 KB
testcase_02 AC 1,080 ms
75,392 KB
testcase_03 AC 1,128 ms
77,696 KB
testcase_04 AC 1,149 ms
77,824 KB
testcase_05 AC 1,176 ms
77,568 KB
testcase_06 AC 1,167 ms
77,312 KB
testcase_07 AC 1,076 ms
75,648 KB
testcase_08 AC 1,085 ms
75,392 KB
testcase_09 AC 1,085 ms
75,520 KB
testcase_10 AC 1,083 ms
75,264 KB
testcase_11 AC 1,083 ms
75,392 KB
testcase_12 AC 1,092 ms
75,648 KB
testcase_13 AC 1,083 ms
75,776 KB
testcase_14 AC 1,089 ms
75,520 KB
testcase_15 AC 1,084 ms
75,776 KB
testcase_16 AC 1,082 ms
75,904 KB
testcase_17 AC 1,232 ms
95,488 KB
testcase_18 AC 1,255 ms
86,528 KB
testcase_19 AC 1,569 ms
129,408 KB
testcase_20 AC 1,232 ms
86,528 KB
testcase_21 AC 1,361 ms
118,144 KB
testcase_22 AC 1,121 ms
81,280 KB
testcase_23 AC 1,188 ms
81,024 KB
testcase_24 AC 1,323 ms
95,616 KB
testcase_25 AC 1,241 ms
95,616 KB
testcase_26 AC 1,278 ms
113,792 KB
testcase_27 AC 1,784 ms
222,976 KB
testcase_28 AC 2,163 ms
265,048 KB
testcase_29 AC 2,030 ms
265,180 KB
testcase_30 AC 2,157 ms
265,176 KB
testcase_31 AC 2,155 ms
265,172 KB
testcase_32 AC 2,256 ms
265,040 KB
testcase_33 AC 2,274 ms
265,048 KB
testcase_34 AC 2,115 ms
264,920 KB
testcase_35 AC 2,161 ms
265,236 KB
testcase_36 AC 2,139 ms
265,044 KB
testcase_37 AC 2,498 ms
265,048 KB
testcase_38 AC 2,551 ms
264,784 KB
testcase_39 AC 2,147 ms
264,984 KB
testcase_40 AC 2,471 ms
264,916 KB
testcase_41 AC 2,110 ms
265,180 KB
testcase_42 AC 2,376 ms
265,052 KB
testcase_43 AC 2,283 ms
265,040 KB
testcase_44 AC 2,191 ms
264,660 KB
testcase_45 AC 2,146 ms
264,800 KB
testcase_46 AC 2,434 ms
265,048 KB
testcase_47 AC 1,074 ms
75,648 KB
testcase_48 AC 1,079 ms
75,392 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(500):
    Right[i] = pow(revR,i,P)
    
Left =defaultdict(int)
R100=pow(R,500,P)

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