結果
問題 | No.2324 Two Countries within UEC |
ユーザー |
|
提出日時 | 2023-05-28 13:37:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 268 ms / 2,000 ms |
コード長 | 451 bytes |
コンパイル時間 | 488 ms |
コンパイル使用メモリ | 65,716 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 23:13:17 |
合計ジャッジ時間 | 7,269 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
#include<iostream>using namespace std;int inv(int x,int P){int b=P-2;int e=1;while(b){if(b&1)e=(long)e*x%P;b>>=1;x=(long)x*x%P;}return e;}int main(){int N,M,P,Q;cin>>N>>M>>P>>Q;for(;Q--;){int x,f;cin>>x>>f;if(x%P==0){if(f%P==0)cout<<M<<"\n";else cout<<"0\n";}else{int y=(long)f*inv(x,P)%P;if(y>M)cout<<"0\n";else if(y==0)cout<<M/P<<"\n";else cout<<(M-y)/P+1<<"\n";}}}