public void Run() { { var line = Input.ReadLongArray(); N = line[0]; A = line[1]; B = line[2]; K = line[3]; } var comb = new FermatCombination(300000); long ret = 0; for (long a = 0; a <= N; a++) { long R = K - a * A; if (R >= 0 && R % B == 0 && R / B <= N) { long b = R / B; ret += comb.Combination(N, a) * comb.Combination(N, b); ret %= M; } } Console.WriteLine(ret); }
public void Run() { var comb = new FermatCombination(1000000); N = Input.ReadInt(); long ret = 0; { var v = comb.Permutation(N - 1, N - 1); ret += (v * (N)) % MOD; ret %= MOD; } for (int k = 0; k < N; k++) { // C(K ? 1, N ? 1 ? K) × K! × (N ? 1 ? K)! if (k - 1 < N - 1 - k) { continue; } var v1 = comb.Combination(k - 1, N - 1 - k); var v2 = comb.Permutation(k, k); var v3 = comb.Permutation(N - 1 - k, N - 1 - k); var v = (((v1 * v2) % MOD) * v3) % MOD; ret += (MOD - v); ret %= MOD; } Console.WriteLine(ret); }