結果

問題 No.834 Random Walk Trip
ユーザー bal4ubal4u
提出日時 2019-08-14 19:17:07
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 829 bytes
コンパイル時間 652 ms
コンパイル使用メモリ 30,672 KB
実行使用メモリ 5,820 KB
最終ジャッジ日時 2023-10-19 18:13:12
合計ジャッジ時間 1,369 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 10 ms
5,820 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 9 ms
5,708 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 99 ms
4,960 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 127 ms
5,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.834 Random Walk Trip
// bal4u 2019.8.14

#include <stdio.h>

typedef long long ll;
#define MOD 1000000007
#define MAX 1000005

int fact[MAX+2] = {1,1};

int ext_gcd(int a, int b, int *x, int *y) {
	int d;
	if (b == 0) { *x = 1; *y = 0; return a; }
	d = ext_gcd(b, a % b, y, x);
	*y -= a / b * (*x);
	return d;
}

int inverse(int a) {
    int x, y;
    ext_gcd(a, MOD, &x, &y);
	return x % MOD;
}

int comb(int n, int k) {
    return (ll)fact[n] * inverse(((ll)fact[k] * fact[n-k]) % MOD) % MOD;
}

int main()
{
	int i, N, M, ans;

	scanf("%d%d", &N, &M);
	if (N == 1) { puts("1"); return 0; }
	
	for (i = 2; i <= M; i++) fact[i] = (ll)fact[i-1]*i % MOD;
	ans = 0;
	i = (M >> 1) % N;
	while (i <= M) {
		ans = (ans + comb(M, i)) % MOD;
		i += N;
	}
	if (ans < 0) ans += MOD;
	printf("%d\n", ans);
    return 0;
}
0