結果

問題 No.2324 Two Countries within UEC
ユーザー m_99
提出日時 2023-05-28 13:37:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 243 ms / 2,000 ms
コード長 725 bytes
コンパイル時間 3,616 ms
コンパイル使用メモリ 228,208 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 23:12:23
合計ジャッジ時間 10,089 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){
	
	int N,M;
	cin>>N>>M;
	int P,Q;
	cin>>P>>Q;
	rep(i,Q){
		int x,y;
		cin>>x>>y;
		if(y==0){
			if(x%P==0){
				cout<<M<<endl;
			}
			else{
				cout<<M/P<<endl;
			}
		}
		else{
			if(x%P==0){
				if(y==0){
				cout<<M<<endl;
				continue;
				}
				else{
					cout<<0<<endl;
					continue;
				}
			}
			long long t = y;
			t *= inv_mod(x,P);
			t %= P;
		//	cout<<t<<endl;
			long long ans = M/P;
			if(M%P>=t)ans++;
			cout<<ans<<endl;
		}
	}
	
	return 0;
}
0