結果
問題 | No.2324 Two Countries within UEC |
ユーザー |
![]() |
提出日時 | 2023-05-28 13:56:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 100 ms / 2,000 ms |
コード長 | 751 bytes |
コンパイル時間 | 660 ms |
コンパイル使用メモリ | 66,432 KB |
最終ジャッジ日時 | 2025-02-13 10:30:31 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
#include <iostream> using namespace std; typedef long long ll; ll pw(ll a,ll x,ll mod){ ll ret = 1; while(x){ if(x&1) (ret *= a) %= mod; (a *= a) %= mod; x /= 2; } return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll i,n,m,p,q; cin >> n >> m >> p >> q; for(i=0;i<q;i++){ ll x,f; cin >> x >> f; x %= p; if(x==0){ if(f==0){ cout << m << "\n"; }else{ cout << 0 << "\n"; } }else{ ll y = (pw(x,p - 2,p)*f)%p; if(!y){ cout << (m - y)/p << "\n"; }else{ cout << (m - y + p)/p << "\n"; } } } }