結果

問題 No.2324 Two Countries within UEC
ユーザー keisuke6keisuke6
提出日時 2023-05-28 14:56:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 842 bytes
コンパイル時間 3,034 ms
コンパイル使用メモリ 199,832 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-09 06:14:16
合計ジャッジ時間 10,592 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 251 ms
4,376 KB
testcase_01 AC 266 ms
4,376 KB
testcase_02 AC 48 ms
4,380 KB
testcase_03 AC 196 ms
4,380 KB
testcase_04 AC 227 ms
4,380 KB
testcase_05 AC 50 ms
4,380 KB
testcase_06 AC 91 ms
4,376 KB
testcase_07 AC 41 ms
4,380 KB
testcase_08 AC 196 ms
4,380 KB
testcase_09 AC 204 ms
4,380 KB
testcase_10 AC 267 ms
4,380 KB
testcase_11 AC 256 ms
4,380 KB
testcase_12 AC 80 ms
4,380 KB
testcase_13 AC 79 ms
4,500 KB
testcase_14 AC 48 ms
4,380 KB
testcase_15 AC 42 ms
4,380 KB
testcase_16 AC 179 ms
4,380 KB
testcase_17 AC 113 ms
4,376 KB
testcase_18 AC 52 ms
4,376 KB
testcase_19 AC 271 ms
4,380 KB
testcase_20 AC 35 ms
4,384 KB
testcase_21 AC 171 ms
4,380 KB
testcase_22 AC 220 ms
4,380 KB
testcase_23 AC 69 ms
4,376 KB
testcase_24 AC 183 ms
4,376 KB
testcase_25 AC 265 ms
4,380 KB
testcase_26 AC 198 ms
4,376 KB
testcase_27 AC 205 ms
4,376 KB
testcase_28 AC 195 ms
4,376 KB
testcase_29 AC 194 ms
4,380 KB
testcase_30 AC 196 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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);
  	if(t%z != 0){
  		cout<<0<<endl;
  		continue;
  	}
  	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;
  	}
  	if(k+10*p >= M){
  		int ans = 0;
  		while(k <= M){
  			ans++;
  			k += p;
  		}
  		cout<<ans<<endl;
  		continue;
  	}
  	cout<<max(0ll,(M+(p-k))/p)<<endl;
  }
}
0