2023-05-26

Python - Count all combinations of K numbers from 1-N whose sum is equal to N

How do i count all combinations of k numbers from 1-n whose sum is equal to n? Like for n = 10, k = 3, we have (1, 2, 7), (1, 3, 6), (1, 4, 5), (2, 3, 5)

I've tried using itertools.combination but it grows really fast for big numbers



No comments:

Post a Comment