結果
| 問題 | 
                            No.834 Random Walk Trip
                             | 
                    
| コンテスト | |
| ユーザー | 
                             bal4u
                         | 
                    
| 提出日時 | 2019-08-14 19:17:07 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 125 ms / 2,000 ms | 
| コード長 | 829 bytes | 
| コンパイル時間 | 358 ms | 
| コンパイル使用メモリ | 30,592 KB | 
| 実行使用メモリ | 5,760 KB | 
| 最終ジャッジ日時 | 2024-09-19 14:33:38 | 
| 合計ジャッジ時間 | 1,395 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 26 | 
ソースコード
// 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;
}
            
            
            
        
            
bal4u