結果

問題 No.2324 Two Countries within UEC
ユーザー kenichikenichi
提出日時 2023-07-14 18:10:01
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 28,556 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 07:58:18
合計ジャッジ時間 4,236 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
4,352 KB
testcase_01 AC 95 ms
4,352 KB
testcase_02 AC 18 ms
4,348 KB
testcase_03 AC 68 ms
4,352 KB
testcase_04 AC 78 ms
4,352 KB
testcase_05 AC 18 ms
4,348 KB
testcase_06 AC 31 ms
4,352 KB
testcase_07 AC 15 ms
4,352 KB
testcase_08 AC 66 ms
4,348 KB
testcase_09 AC 68 ms
4,352 KB
testcase_10 AC 95 ms
4,352 KB
testcase_11 AC 88 ms
4,352 KB
testcase_12 AC 28 ms
4,348 KB
testcase_13 AC 28 ms
4,348 KB
testcase_14 AC 17 ms
4,348 KB
testcase_15 AC 14 ms
4,348 KB
testcase_16 AC 64 ms
4,348 KB
testcase_17 AC 41 ms
4,352 KB
testcase_18 AC 18 ms
4,348 KB
testcase_19 AC 94 ms
4,352 KB
testcase_20 AC 13 ms
4,348 KB
testcase_21 AC 39 ms
4,352 KB
testcase_22 AC 53 ms
4,356 KB
testcase_23 AC 16 ms
4,352 KB
testcase_24 AC 42 ms
4,352 KB
testcase_25 AC 93 ms
4,352 KB
testcase_26 AC 32 ms
4,348 KB
testcase_27 AC 33 ms
4,352 KB
testcase_28 AC 31 ms
4,348 KB
testcase_29 AC 31 ms
4,352 KB
testcase_30 AC 31 ms
4,352 KB
testcase_31 AC 1 ms
4,352 KB
testcase_32 AC 1 ms
4,348 KB
testcase_33 AC 0 ms
4,348 KB
testcase_34 AC 1 ms
4,348 KB
testcase_35 AC 1 ms
4,348 KB
testcase_36 AC 1 ms
4,352 KB
testcase_37 AC 1 ms
4,352 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 0 ms
4,348 KB
testcase_41 AC 0 ms
4,352 KB
testcase_42 AC 0 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
long long int modpow(long long int a, long long int n, long long int p)
{
	long long int res = 1;
	for (; n > 0; n /= 2, a = a * a % p)
		if (n % 2 > 0)
			res = res * a % p;
	return res;
}
int main()
{
	long long int n, m, p, q;
	scanf("%lld %lld %lld %lld", &n, &m, &p, &q);
	long long int y;
	long long int x, f;
	long long int ans;
	for (; q > 0; q--)
	{
		scanf("%lld %lld", &x, &f);
		if (x % p == 0)
		{
			if (f == 0)
				ans = m;
			else
				ans = 0;
		}
		else
		{
			y = f * modpow(x, p - 2, p) % p;
			ans = m / p;
			if (y <= m % p && y != 0)
				ans++;
		}
		printf("%lld\n", ans);
	}
	return 0;
}
0