結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
63,828 KB
testcase_01 AC 99 ms
64,896 KB
testcase_02 AC 105 ms
66,572 KB
testcase_03 AC 165 ms
77,728 KB
testcase_04 AC 174 ms
78,044 KB
testcase_05 AC 193 ms
78,336 KB
testcase_06 AC 203 ms
78,212 KB
testcase_07 AC 98 ms
65,212 KB
testcase_08 AC 100 ms
65,420 KB
testcase_09 AC 100 ms
64,876 KB
testcase_10 AC 98 ms
64,572 KB
testcase_11 AC 98 ms
65,600 KB
testcase_12 AC 99 ms
64,620 KB
testcase_13 AC 102 ms
65,436 KB
testcase_14 AC 93 ms
64,800 KB
testcase_15 AC 96 ms
65,216 KB
testcase_16 AC 91 ms
64,452 KB
testcase_17 AC 113 ms
80,504 KB
testcase_18 AC 108 ms
76,848 KB
testcase_19 AC 123 ms
82,252 KB
testcase_20 AC 125 ms
76,936 KB
testcase_21 AC 120 ms
74,676 KB
testcase_22 AC 109 ms
71,796 KB
testcase_23 AC 95 ms
66,600 KB
testcase_24 AC 105 ms
75,748 KB
testcase_25 AC 103 ms
80,960 KB
testcase_26 AC 107 ms
80,084 KB
testcase_27 AC 545 ms
93,100 KB
testcase_28 AC 638 ms
93,092 KB
testcase_29 AC 298 ms
93,072 KB
testcase_30 AC 985 ms
93,292 KB
testcase_31 AC 298 ms
93,072 KB
testcase_32 AC 1,172 ms
93,300 KB
testcase_33 AC 501 ms
93,020 KB
testcase_34 AC 401 ms
93,092 KB
testcase_35 AC 315 ms
92,956 KB
testcase_36 AC 332 ms
93,044 KB
testcase_37 AC 2,512 ms
93,240 KB
testcase_38 AC 1,992 ms
93,128 KB
testcase_39 AC 579 ms
92,952 KB
testcase_40 AC 1,291 ms
93,028 KB
testcase_41 AC 936 ms
92,992 KB
testcase_42 AC 2,442 ms
93,124 KB
testcase_43 AC 659 ms
92,952 KB
testcase_44 AC 1,179 ms
93,148 KB
testcase_45 AC 750 ms
92,992 KB
testcase_46 AC 2,388 ms
93,092 KB
testcase_47 AC 89 ms
65,140 KB
testcase_48 AC 89 ms
65,204 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(10000):
    Right[i] = pow(revR,i,P)
    
Left =defaultdict(int)
R100=pow(R,10000,P)

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