結果

問題 No.2324 Two Countries within UEC
ユーザー keisuke6
提出日時 2023-05-28 13:57:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 660 bytes
コンパイル時間 1,942 ms
コンパイル使用メモリ 193,212 KB
最終ジャッジ日時 2025-02-13 10:31:18
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
signed main(){
  int N,M,P,Q;
  cin>>N>>M>>P>>Q;
  for(int i=0;i<Q;i++){
  	int x,t;
  	cin>>x>>t;
  	x %= P;
  	int p = P;
  	int z = gcd(p,x);
  	p /= z;
  	x /= z;
  	if(p == 1){
  		cout<<M<<endl;
  		continue;
  	}
  	int k = modinv(x,p)*t%p;
  	if(t == 0){
  		cout<<M/p<<endl;
  		continue;
  	}
  	cout<<max(0ll,(M+(p-k))/p)<<endl;
  }
}
0