Розбір
Consider a sequence of ones: . You can insert a ‘’ sign between any two ones. For example, . Such notation denotes the sum , where each term represents the number of ones adjacent to each other. The number of positions where a ‘’ sign can be inserted is . Since the sum must consist of terms, ‘’ signs should be inserted.
We should insert pluses in places. This can be done in ways.
Example
Consider the equation . It has positive integer solutions: .
For example, ones can be divided into terms in ways:
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 - 1); printf("%lld\n", res);
Python реализация
import math
Read the input data.
k, n = map(int,input().split())
Compute and print the answer – the value of .
res = math.comb(n - 1, k - 1) print(res)