In how many ways can 7^23 be expressed as a product of five natural numbers?
Also repeat the problem for 7^22.
The 5 factors are all powers of 7, from 7^0 up to 7^23.
This is equivalent to taking the integers 0 through 23, putting them into 5 bins provided the sum of the 5 bins is 23. I figured both combinations and permutations.
Output:
7^23:
If order does not matter:
291
If order matters:
17550
7^22
If order does not matter:
255
If order matters:
14950
I wrote a function for dividing n items into g groups.
def groups(smallest,n,g,listing=False):
""" Ways to divide n items into g groups, when the smallest number of items in a bin is 'smallest'; returns the full list of ways if the 4th parameter is True, or just the count if False. """
poss = [i for i in range(smallest, n+1)]
ans = []
for comb in combinations_with_replacement(poss,g):
comb = list(comb)
if comb != sorted(comb):
continue
if sum(comb) != n:
continue
ans.append(comb)
if listing:
return ans
else:
return len(ans)
number = 23
bins = 5
print('If order does not matter:','
', groups(0,number,bins))
print('If order matters:')
mylist = groups(0,number,bins,True)
grandlist = []
for m in mylist:
instances = []
for digit in set(m):
instances.append(m.count(digit))
factorial_list = [fact(d) for d in instances]
grandlist.append(int(fact(bins)/product(factorial_list)))
print('',sum(grandlist))
Edited on February 28, 2025, 7:23 pm
|
Posted by Larry
on 2025-02-28 17:04:06 |