Q:

Python giving a memory error

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

A:

If you really need to use this large data set, you should use pandas or numpy to process it.
But if you're trying to solve a coding golf, try to use a smaller data set to test your approach. Anyway, you may consider use iterators instead list, and use iterator.chain to join iterators. 
from itertools import chain

A=int(input())
B=int(input())
N=int(input())

array_a = (i*A for i in range(10**4))
array_b = (i*B for i in range(10**4))
array_c = chain(array_a, array_b)
c = sorted(set(array_c))

print(c[N])

