結果
問題 |
No.551 夏休みの思い出(2)
|
ユーザー |
|
提出日時 | 2019-02-22 19:38:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 873 ms / 4,000 ms |
コード長 | 991 bytes |
コンパイル時間 | 1,023 ms |
コンパイル使用メモリ | 83,488 KB |
実行使用メモリ | 27,784 KB |
最終ジャッジ日時 | 2024-11-24 23:28:29 |
合計ジャッジ時間 | 10,388 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 47 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> #include<vector> #include<cmath> using namespace std; long P,R; long power(long a,long b){return b?power(a*a%P,b/2)*(b%2?a:1)%P:1;} main() { int q;cin>>P>>R>>q; int m=sqrt(q*P); vector<pair<int,int> >table(m); long e=1; for(int i=0;i<m;i++) { table[i]=make_pair(e,i); e=e*R%P; } sort(table.begin(),table.end()); long inv=power(power(R,P-2),m); for(;q--;) { long a,b,c;cin>>a>>b>>c; long d=(b*b%P-4*a*c%P+P)%P*power(4*a*a%P,P-2)%P; long t=(P-b*power(2*a%P,P-2)%P)%P; if(d==0) { cout<<t<<endl; } else { long k,now=d; for(int i=0;;i++) { pair<int,int>p=*lower_bound(table.begin(),table.end(),make_pair((int)now,-1)); if(p.first==now) { k=i*m+p.second; break; } now=now*inv%P; } if(k%2==0) { long x=(power(R,k/2)+t)%P,y=(power(R,(k/2+P/2)%(P-1))+t)%P; if(x<y)cout<<x<<" "<<y<<endl; else cout<<y<<" "<<x<<endl; } else { cout<<-1<<endl; } } } }