結果

問題 No.2324 Two Countries within UEC
ユーザー shobonvipshobonvip
提出日時 2023-05-28 13:50:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 770 bytes
コンパイル時間 4,980 ms
コンパイル使用メモリ 259,056 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-09 06:08:25
合計ジャッジ時間 11,654 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 260 ms
4,384 KB
testcase_01 AC 267 ms
4,380 KB
testcase_02 AC 49 ms
4,380 KB
testcase_03 AC 204 ms
4,380 KB
testcase_04 AC 227 ms
4,500 KB
testcase_05 AC 51 ms
4,380 KB
testcase_06 AC 91 ms
4,380 KB
testcase_07 AC 41 ms
4,380 KB
testcase_08 AC 194 ms
4,380 KB
testcase_09 AC 204 ms
4,380 KB
testcase_10 AC 266 ms
4,376 KB
testcase_11 AC 260 ms
4,380 KB
testcase_12 AC 80 ms
4,376 KB
testcase_13 AC 81 ms
4,380 KB
testcase_14 AC 50 ms
4,380 KB
testcase_15 AC 41 ms
4,380 KB
testcase_16 AC 184 ms
4,380 KB
testcase_17 AC 118 ms
4,376 KB
testcase_18 AC 51 ms
4,380 KB
testcase_19 AC 265 ms
4,380 KB
testcase_20 AC 35 ms
4,376 KB
testcase_21 AC 163 ms
4,376 KB
testcase_22 AC 205 ms
4,376 KB
testcase_23 AC 68 ms
4,380 KB
testcase_24 AC 173 ms
4,380 KB
testcase_25 AC 275 ms
4,376 KB
testcase_26 AC 189 ms
4,380 KB
testcase_27 AC 197 ms
4,376 KB
testcase_28 AC 189 ms
4,376 KB
testcase_29 AC 186 ms
4,380 KB
testcase_30 AC 189 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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 == 0){
				cout << base << "\n";
			}else if (tar <= amari){
				cout << base + 1 << "\n";
			}else{
				cout << base << "\n";
			}
		}
	}
}
0