結果
問題 | No.551 夏休みの思い出(2) |
ユーザー |
![]() |
提出日時 | 2020-08-12 13:49:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,498 ms / 4,000 ms |
コード長 | 993 bytes |
コンパイル時間 | 157 ms |
コンパイル使用メモリ | 82,264 KB |
実行使用メモリ | 93,296 KB |
最終ジャッジ日時 | 2024-10-09 18:12:48 |
合計ジャッジ時間 | 25,123 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
ソースコード
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)