結果

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

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

ll mod_pow(ll x, ll m, int P){
	ll ret = 1;
	ll tmp = x;
	while (m > 0){
		if (m&1){
			ret = ret * tmp % P;
		}
		m >>= 1;
		tmp = tmp * tmp % P;
	}
	return ret;
}

int main(){
	ll n, m, p; cin >> n >> m >> p;
	int q; cin >> q;
	ll base = m / p;
	ll amari = m % p;
	for (int i=0; i<q; i++){
		ll x, f; cin >> x >> f;
		if (x % p == 0){
			if (f == 0){
				cout << m << "\n";
			}else{
				cout << 0 << "\n";
			}
		}else{
			ll tar = mod_pow(x % p, p-2, (int)p) * f % p;
			if ((tar - 1 + p) % p <= amari){
				cout << base + 1 << "\n";
			}else{
				cout << base << "\n";
			}
		}
	}
}
0