結果

問題 No.2120 場合の数の下8桁
ユーザー 👑 ygussanyygussany
提出日時 2022-11-04 21:50:30
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 98 ms / 2,000 ms
コード長 1,103 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 30,360 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 00:13:12
合計ジャッジ時間 1,452 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 98 ms
4,380 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 0 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 29 ms
4,380 KB
testcase_16 AC 94 ms
4,380 KB
testcase_17 AC 48 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 51 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 100000000;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long pow_mod(int n, long long k)
{
	long long N, ans = 1;
	for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod;
	return ans;
}

int main()
{
	int N, M;
	scanf("%d", &M);
	scanf("%d", &N);
	if (M < N) {
		printf("00000000\n");
		fflush(stdout);
		return 0;
	}
	
	int i, k, num2[2] = {}, num5[2] = {};
	long long rest[2] = {1, 1};
	for (i = M; i > M - N; i--) {
		k = i;
		while (k % 2 == 0) {
			k /= 2;
			num2[0]++;
		}
		while (k % 5 == 0) {
			k /= 5;
			num5[0]++;
		}
		rest[0] = rest[0] * k % Mod;
	}
	for (i = 2; i <= N; i++) {
		k = i;
		while (k % 2 == 0) {
			k /= 2;
			num2[1]++;
		}
		while (k % 5 == 0) {
			k /= 5;
			num5[1]++;
		}
		rest[1] = rest[1] * k % Mod;
	}
	
	long long ans = div_mod(rest[0], rest[1], Mod) * pow_mod(2, num2[0] - num2[1]) % Mod * pow_mod(5, num5[0] - num5[1]) % Mod;
	printf("%08lld\n", ans);
	fflush(stdout);
	return 0;
}
0