結果
問題 |
No.551 夏休みの思い出(2)
|
ユーザー |
![]() |
提出日時 | 2020-08-12 00:48:16 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 983 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 82,200 KB |
実行使用メモリ | 82,668 KB |
最終ジャッジ日時 | 2024-10-09 12:05:37 |
合計ジャッジ時間 | 11,811 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 2 |
other | TLE * 1 -- * 46 |
ソースコード
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(100): Right[i] = pow(revR,i,P) Left =defaultdict(int) R100=pow(R,100,P) for i in range(10**7): 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(100): key= Right[j]*T%P if key in Left.keys(): order = 100* Left[key] + j break order =order % P 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)