結果
問題 | No.2324 Two Countries within UEC |
ユーザー |
|
提出日時 | 2023-05-28 14:07:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 283 ms / 2,000 ms |
コード長 | 579 bytes |
コンパイル時間 | 1,936 ms |
コンパイル使用メモリ | 192,316 KB |
最終ジャッジ日時 | 2025-02-13 10:52:26 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for (int i=0;i<(int)(n);i++) ll mpow(ll x,ll n,ll mod){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int main(){ int n,m,p,q; cin>>n>>m>>p>>q; rep(Qi,q){ int x,f; cin>>x>>f; if(f==0){ if(x%p==0) cout<<m<<endl; else{ cout<<m/p<<endl; } continue; } if(x%p==0){ cout<<0<<endl; continue; } ll res=mpow(x,p-2,p); res=res*f%p; cout<<(m+p-res)/p<<endl; } }