Back to General discussions forum
Hi Experts,
My method involved first determining 'n' for each prime by dividing the maximum number of plants by that prime. Subsequently, I calculated how frequently they share common multiples by dividing the maximum number of plants by the least common multiple (LCM) of all possible pairs of numbers (considering two numbers at a time). Finally, I computed 'N' as the sum of the maximum number of plants, the sum of common multiples, and the subtraction of the sum of 'n'.
While this approach yields correct results for small numbers, it falls short when dealing with larger numbers. Can someone kindly explain the reasons behind this discrepancy?"
with open("C:\\samb\\myfile.txt") as my_file:
clue_list = my_file.readlines()
clue_list = [elements.split() for elements in clue_list]
num_list = [[int(i) for i in item] for item in clue_list]
print(num_list)
for items in num_list:
max_plant = items[0]
primes = items[1::]
p_combinations = list(combinations(primes, 2))
multiples = 0
commons = 0
for p in primes:
multiples1 = max_plant // p
multiples += multiples1
for c in p_combinations:
commons1 = max_plant // math.lcm(c[0],c[1])
commons += commons1
print(max_plant - multiples + commons )
Why stop at pairs of numbers? Why are you not considering triples, quadruples etc? Try some simple examples and have a close look at what is actually happening. You have the basis of a correct approach but you need to develop this further.
Done and Dusted!!! Thanks!!!