Jan-17-2022, 07:37 PM
(Jan-17-2022, 04:46 PM)Frankduc Wrote: Also is it possible to initialize the variable count at the top so that the numbers count appear just after Primes sum that gives:?Do you mean like this?
import itertools lim = int(input("Generate prime numbers up to : ")) listo = [] def prime_eratosthenes(lim): prime_list = [] for i in range(2, lim+1): if i not in prime_list: print (i, end = ' ') listo.append(i) for j in range(i*i, lim+1, i): prime_list.append(j) # print(j) return listo def printPairs(lim): primes = prime_eratosthenes(lim) for i in range(0, len(primes)): for j in range(i+1, len(primes)): if (primes[i]*primes[j])==lim: print(' ') print("Primes multiply that gives: ",lim) print(primes[i], primes[j]) printPairs(lim) som = 0 count = 0 for L in range(0, len(listo)+1): for subset in itertools.combinations(listo, L): som = sum(subset) if (som == lim): print(som, subset) count += 1 print('') print('Primes sum that gives:', lim) print("Number of pairs: ", count)Also, if you give it an 85 or 86 to chew on, you can see how long it takes. I think 100 is just overloading something.