結果
問題 | No.2324 Two Countries within UEC |
ユーザー |
|
提出日時 | 2023-05-28 17:37:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 254 ms / 2,000 ms |
コード長 | 664 bytes |
コンパイル時間 | 2,029 ms |
コンパイル使用メモリ | 166,412 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 23:31:08 |
合計ジャッジ時間 | 8,594 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll=long long; ll modinv(ll a,ll m){ ll b=m,u=1,v=0; while(b){ ll t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } u%=m; if(u<0){ u+=m; } return u; } int main(){ ll n,m,p,q; cin>>n>>m>>p>>q; while(q--){ ll x,f; cin>>x>>f; x%=p; if(x==0){ if(f==0){ cout<<m<<endl; }else{ cout<<0<<endl; } }else{ ll inv=modinv(x,p); ll y=f*inv; y%=p; ll cnt=(m-y)/p+1; if(m-y<0){ cout<<0<<endl; }else{ if(y==0){ cnt--; } cout<<cnt<<endl; } } } }