Redaksiya
Consider a sequence of positions. In positions we should place . In positions we should place the '' symbol (to obtain terms).
Any arrangement of s and '' signs among these positions will correspond to some solution of the given equation. For example, consider some solutions of the equation ones and plus signs):
We should insert plus signs into positions. This can be done in ways.
Example
Consider the equation . Its solutions are:
and its permutations
and its permutations'
and its permutations
and its permutations
There are solutions.
Algorithm realization
The Cnk function computes the value of the binomial coefficient .
long long Cnk(long long k, long long n) { long long res = 1; if (k > n - k) k = n - k; for (long long i = 1; i <= k; i++) res = res * (n - i + 1) / i; return res; }
The main part of the program. Read the input data.
scanf("%lld %lld", &k, &n);
Compute and print the answer — the value of .
res = Cnk(k - 1, n + k - 1); printf("%lld\n", res);
Python realization
import math
Read the input data.
k, n = map(int,input().split())
Вычисляем и выводим ответ .
res = math.comb(n + k - 1, k - 1) print(res)