結果

問題 No.3394 Big Binom
コンテスト
ユーザー pengin_2000
提出日時 2025-12-04 03:18:17
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 1,954 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 246 ms
コンパイル使用メモリ 27,724 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-14 20:03:18
合計ジャッジ時間 2,324 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:14:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%lld %lld", &n, &k);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#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 fact7[102] = { 1,295201906,160030060,957629942,545208507,213689172,760025067,939830261,506268060,39806322,808258749,440133909,686156489,741797144,390377694,12629586,544711799,104121967,495867250,421290700,117153405,57084755,202713771,675932866,79781699,956276337,652678397,35212756,655645460,468129309,761699708,533047427,287671032,206068022,50865043,144980423,111276893,259415897,444094191,593907889,573994984,892454686,566073550,128761001,888483202,251718753,548033568,428105027,742756734,546182474,62402409,102052166,826426395,159186619,926316039,176055335,51568171,414163604,604947226,681666415,511621808,924112080,265769800,955559118,763148293,472709375,19536133,860830935,290471030,851685235,242726978,169855231,612759169,599797734,961628039,953297493,62806842,37844313,909741023,689361523,887890124,380694152,669317759,367270918,806951470,843736533,377403437,945260111,786127243,80918046,875880304,364983542,623250998,598764068,804930040,24257676,214821357,791011898,954947696,183092975,0 };
	long long int n, k;
	scanf("%lld %lld", &n, &k);
	if (k > n - k)
		k = n - k;
	const long long int p = 998244353;
	long long int a, b, c, i;
	long long int e = 10000000;
	if (n >= p)
	{
		if (n - k < p)
			printf("0\n");
		else
		{
			a = b = 1;
			for (i = 0; i < k; i++)
			{
				a = a * (n - i) % p;
				b = b * (i + 1) % p;
			}
			printf("%lld\n", a * modpow(b, p - 2, p) % p);
		}
	}
	else
	{
		a = fact7[n / e];
		for (i = n / e * e + 1; i <= n; i++)
			a = a * i % p;
		b = fact7[k / e];
		for (i = k / e * e + 1; i <= k; i++)
			b = b * i % p;
		c = fact7[(n - k) / e];
		for (i = (n - k) / e * e + 1; i <= n - k; i++)
			c = c * i % p;
		printf("%lld\n", a * modpow(b * c % p, p - 2, p) % p);
	}
	return 0;
}
0