from math import comb def count_smooth_permutations(a, b, c, p): n = a + b - 1 num_permutations = (comb(n, a) * comb(n-1, b-1)) % p print(n, num_permutations) count_smooth_permutations(2, 2, 3, 10000019) count_smooth_permutations(2, 3, 3, 999999937) count_smooth_permutations(8, 9, 11, 15872567)
1 2 3 4 5 6 7 8 9 10 11 12 13 | from math import comb def count_smooth_permutations(a, b, c, p): n = a + b - 1 num_permutations = (comb(n, a) * comb(n-1, b-1)) % p print(n, num_permutations) count_smooth_permutations(2, 2, 3, 10000019) count_smooth_permutations(2, 3, 3, 999999937) count_smooth_permutations(8, 9, 11, 15872567) |