結果
| 問題 |
No.2324 Two Countries within UEC
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2023-05-28 13:58:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 2,000 ms |
| コード長 | 646 bytes |
| コンパイル時間 | 2,014 ms |
| コンパイル使用メモリ | 192,564 KB |
| 最終ジャッジ日時 | 2025-02-13 10:32:15 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 41 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll modpow(ll x,ll n,ll MOD){
x%=MOD;
ll ans=1;
while(n){
if(n&1) ans=ans*x%MOD;
x=x*x%MOD;
n/=2;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n,m,p,q;
cin>>n>>m>>p>>q;
while(q--){
ll x,f;
cin>>x>>f;
if(x%p==0){
if(f==0) cout<<m<<'\n';
else cout<<0<<'\n';
}
else{
ll y=f*modpow(x,p-2,p)%p;
ll ans=m/p;
if(y && m%p>=y) ans++;
cout<<ans<<'\n';
}
}
return 0;
}
umezo