結果

問題 No.551 夏休みの思い出(2)
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-08-12 13:45:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,269 ms / 4,000 ms
コード長 989 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 223,624 KB
最終ジャッジ日時 2024-04-18 00:25:53
合計ジャッジ時間 36,667 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 485 ms
75,492 KB
testcase_01 AC 470 ms
75,592 KB
testcase_02 AC 479 ms
75,788 KB
testcase_03 AC 536 ms
77,292 KB
testcase_04 AC 539 ms
77,488 KB
testcase_05 AC 555 ms
78,132 KB
testcase_06 AC 555 ms
77,272 KB
testcase_07 AC 474 ms
75,440 KB
testcase_08 AC 477 ms
75,604 KB
testcase_09 AC 475 ms
75,672 KB
testcase_10 AC 479 ms
75,644 KB
testcase_11 AC 471 ms
75,896 KB
testcase_12 AC 471 ms
76,060 KB
testcase_13 AC 488 ms
75,632 KB
testcase_14 AC 482 ms
75,856 KB
testcase_15 AC 476 ms
75,772 KB
testcase_16 AC 489 ms
75,584 KB
testcase_17 AC 522 ms
95,780 KB
testcase_18 AC 508 ms
86,800 KB
testcase_19 AC 557 ms
129,624 KB
testcase_20 AC 507 ms
86,560 KB
testcase_21 AC 540 ms
95,688 KB
testcase_22 AC 494 ms
81,516 KB
testcase_23 AC 490 ms
78,300 KB
testcase_24 AC 508 ms
85,296 KB
testcase_25 AC 521 ms
95,684 KB
testcase_26 AC 525 ms
113,948 KB
testcase_27 AC 822 ms
147,564 KB
testcase_28 AC 941 ms
223,168 KB
testcase_29 AC 836 ms
223,624 KB
testcase_30 AC 884 ms
223,296 KB
testcase_31 AC 877 ms
223,124 KB
testcase_32 AC 869 ms
223,356 KB
testcase_33 AC 869 ms
223,356 KB
testcase_34 AC 847 ms
223,460 KB
testcase_35 AC 841 ms
223,368 KB
testcase_36 AC 819 ms
223,436 KB
testcase_37 AC 1,235 ms
223,236 KB
testcase_38 AC 1,197 ms
223,380 KB
testcase_39 AC 860 ms
223,384 KB
testcase_40 AC 1,177 ms
223,572 KB
testcase_41 AC 870 ms
223,416 KB
testcase_42 AC 1,269 ms
223,300 KB
testcase_43 AC 1,107 ms
223,296 KB
testcase_44 AC 921 ms
223,124 KB
testcase_45 AC 948 ms
223,520 KB
testcase_46 AC 1,206 ms
223,400 KB
testcase_47 AC 473 ms
75,808 KB
testcase_48 AC 474 ms
75,364 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(1000):
    Right[i] = pow(revR,i,P)
    
Left =defaultdict(int)
R100=pow(R,1000,P)

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