hi everyone im very new to python.i was trying to solve this problem from a coding site online
A=3, B= 5
Table of A = 3 , 6 , 9 , 12 ,15 ,18 and so on
Table of B =5 , 10 , 15 , 20 and so on
After Merging : 3, 5, 6, 9 ,10 , 12 ,15 ,15, 18, 20 and so on
Remove Duplicates : 3 , 5 , 6, 9 , 10 , 12 , 15 , 18 , 20 and so on
For N= 2 , 2nd element of the supertable is 5
the problem is i can get the answers for a finite range of A and B but when i do it for 10^9th element i get a memory error.
from array import *
import itertools
array1=[]
array2=[]
A=int(input())
B=int(input())
N=int(input())
for i in range(0,10**9):
try:
array1.append(i+1 * A)
except MemoryError :
break
for j in range(0,10**9):
try:
array2.append(j+1 * B)
except MemoryError :
break
filter(None ,array1)
filter(None ,array2)
array3 = array1 + array2
array3 = sorted(set(array3))
print (array3[N])
Traceback (most recent call last):
File "C:/Users/Clinton D/Desktop/supertables.py", line 21, in
array3 = array1 + array2
MemoryError
xrangealso... you are making some BIG lists.rangeis an iterator in python 3.10**9 x intsize, see this other answer for more info: stackoverflow.com/a/14329864/764322