Problem:


Bamboo Blossoms

  The bamboos live for decades, and at the end of their lives,
  they flower to make their seeds.  Dr. ACM, a biologist, was fascinated
  by the bamboos in blossom in his travel to Tsukuba.  He liked
  the flower so much that he was tempted to make a garden where
  the bamboos bloom annually.  Dr. ACM started research of
  improving breed of the bamboos, and finally, he established
  a method to develop bamboo breeds with controlled lifetimes.
  With this method, he can develop bamboo breeds that flower
  after arbitrarily specified years.

  Let us call bamboos that flower k years after sowing
  "k-year-bamboos."
  k years after being sowed, k-year-bamboos make
  their seeds and then die,
  hence their next generation flowers after another k years.
  In this way, if he sows seeds of k-year-bamboos, he can
  see bamboo blossoms every k years.  For example,
  assuming that he sows seeds of 15-year-bamboos,
  he can see bamboo blossoms every 15 years;
  15 years, 30 years, 45 years, and so on, after sowing.

  Dr. ACM asked you for designing his garden.  His garden is partitioned
  into blocks, in each of which only a single breed of bamboo can grow.
  Dr. ACM requested you to decide which breeds of bamboos
  should he sow in the blocks in order to see bamboo blossoms
  in at least one block for as many years as possible.

  You immediately suggested to sow seeds of one-year-bamboos in all blocks.
  Dr. ACM, however, said that it was difficult to develop a bamboo breed
  with short lifetime, and would like a plan using only those breeds with
  long lifetimes.  He also said that, although he could wait for some years
  until he would see the first bloom, he would like to see it in
  every following year.
  Then, you suggested a plan
  to sow seeds of 10-year-bamboos, for example, in different blocks each year,
  that is, to sow in a block this year and in another block next year, and so on,
  for 10 years.  Following this plan, he could see
  bamboo blossoms in one block every year except for the first 10 years.
  Dr. ACM objected again saying he had determined to sow in all
  blocks this year.

  After all, you made up your mind to make a sowing plan where the bamboos
  bloom in at least one block for as many consecutive years as possible
  after the first m years (including this year)
  under the following conditions:
  

    
the plan should use only those bamboo breeds whose
      lifetimes are m years or longer, and
    
Dr. ACM should sow the seeds in all the blocks only this year.
  

Input

  The input consists of at most 50 datasets, each in the following format.

    m n

  An integer m (2 ≤ m ≤ 100) represents the lifetime
  (in years)
  of the bamboos with the shortest lifetime that Dr. ACM can use for
  gardening.
  An integer n (1 ≤ n ≤ 500,000) represents the number of blocks.

The end of the input is indicated by a line containing two zeros.

Output

  No matter how good your plan is, a "dull-year" would
  eventually come, in which the bamboos do not flower in any block.
  For each dataset, output in a line an integer meaning how many
  years from now the first dull-year comes after the first m years.

  Note that the input of m = 2 and n = 500,000
  (the last dataset of the Sample Input) gives the largest answer.

Sample Input

3 1
3 4
10 20
100 50
2 500000
0 0

Output for the Sample Input

4
11
47
150
7368791



Sample input:
3 1
3 4
10 20
100 50
2 500000
0 0


Sample output:
4
11
47
150
7368791

Submission status: Wrong Answer

Solution code:
def mark(s, x):
    for i in range(x, len(s), x):
        s[i] = False

def sieve(m,n):
    s = [False] * m + [True] * 16 * n
    count = 0
    for x in range(m,n * 16):
        if s[x]:
            mark(s, x)
            count += 1
            if count == n:
                break
    return [i for i in range(len(s)) if s[i] and i > 1]

def main():

    while(True):
        a = list(map(int, input().split()))
        m , n = a[0], a[1]
        if m == 0:
            return(0)
        print(sieve(m,n)[0])

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    M = 7368792

    def f(m, n):
        g = [None] * M
        i = m
        while True:
            if g[i] is None:
                if n == 0:
                    return i
                else:
                    n -= 1
                for j in range(i,M,i):
                    g[j] = 1
            i += 1

    while True:
        m,n = LI()
        if m == 0 and n == 0:
            break
        rr.append(f(m,n))

    return '\n'.join(map(str,rr))




print(main())

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class Prime():
    def __init__(self, m):
        self.M = m + 1
        self.A = a = [True] * self.M
        a[0] = a[1] = 0
        self.T = t = []
        sq = int(math.sqrt(self.M))
        q = 0
        for i in range(2, sq + 1):
            if not a[i]:
                a[i] = q
                continue
            t.append(i)
            a[i] = q
            q += 1
            for j in range(i*i,m,i):
                a[j] = False

        for i in range(sq + 1, self.M):
            if a[i]:
                a[i] = q
                q += 1
                t.append(i)
            else:
                a[i] = q

    def is_prime(self, n):
        return self.A[n]


def main():
    rr = []

    M = 7368792
    pr = Prime(M)

    def f(m, n):
        nn = n
        g = [None] * (m*m)
        for i in range(m, m*m):
            if not g[i]:
                if n == 0:
                    return i
                n -= 1
                for j in range(i, m*m, i):
                    g[j] = 1
        d = pr.A[m*m]
        return pr.T[d+n]

    while True:
        m,n = LI()
        if m == 0 and n == 0:
            break
        rr.append(f(m,n))

    return '\n'.join(map(str,rr))




print(main())

Submission status: Accepted

Solution code:
import math
MAX = 7400000
prime = [1]*MAX
prime[0] = prime[1] = 0
res = []
sq = int(math.sqrt(MAX))
for i in xrange(2, sq+1):
    q = len(res)
    if prime[i]:
        res.append(i)
        for j in xrange(i*i, MAX, i):
            prime[j] = 0
    prime[i] = q
for i in xrange(sq+1, MAX):
    q = len(res)
    if prime[i]:
        res.append(i)
    prime[i] = q

def solve(m, n):
    # [m,m*m)
    sat = [0]*(m*m)
    for i in xrange(m, m*m):
        if not sat[i]:
            if n == 0:
                return i
            n -= 1
            for j in xrange(i, m*m, i):
                sat[j] = 1
    # [m*m,\inf)
    idx = prime[m*m]
    return res[idx+n]
while 1:
    m, n = map(int, raw_input().split())
    if m==0:
        break
    print solve(m, n)

Submission status: Accepted

Solution code:
MAX = 7368792
for e in iter(input, '0 0'):
    m, n = map(int, e.split())
    table = [False] * MAX
    for _ in range(n):
        table[m::m] = [True] * len(table[m::m])
        while table[m]: m += 1
    print(m)

Submission status: Accepted

Solution code:
MAX = 7368792
while True:
    m,n = map(int,input().split())
    if m+n == 0:
        break
    ##
    E = [True]*(MAX)
    k = 0
    for i in range(m,MAX):
        if E[i]:
            n -= 1
            E[i::i] = [False]*((MAX-i-1)//i+1)
            if n!=0:
                continue
            i += 1
            while not E[i]:
                i += 1
            print(i)
            break

Submission status: Accepted

Solution code:
def main(m, n):
    ck = [True] * (7368792)
    for i in range(m, 7368792):
        if ck[i]:
            n -= 1
            ck[i::i]=[False]*((7368791-i)//i+1)
            if n != 0:
                continue
            i += 1
            while not ck[i]:
                i += 1
            print(i)
            return


while 1:
    m, n = map(int, input().split())
    if n == m == 0:
        break
    main(m, n)

Submission status: Accepted

Solution code:
from bisect import bisect_left

def rwh_primes2(n):
    # https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    correction = (n%6>1)
    n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6]
    sieve = [True] * (n//3)
    sieve[0] = False
    for i in range(int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      ((k*k)//3)      ::2*k]=[False]*((n//6-(k*k)//6-1)//k+1)
        sieve[(k*k+4*k-2*k*(i&1))//3::2*k]=[False]*((n//6-(k*k+4*k-2*k*(i&1))//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

if __name__ == "__main__":
  prime = rwh_primes2(7368791+10)
  while True:
    m,n = map(int,input().split())
    if m == 0 and n == 0:
      break
    small_prime = prime[:bisect_left(prime,m**2)]
    composite = []
    for i in range(1,m+1):
      for j in range(i,m+1):
        x = i*j
        if m <= x <= m**2 and x not in small_prime:
          for p in small_prime:
            if x%p == 0:
              if x < m*p:
                composite.append(x)
              break
    composite = sorted(list(set(composite)))
    pp = bisect_left(prime,m)
    cp = 0
    sz = len(composite)
    for i in range(n+1):
      if cp < sz:
        if composite[cp] < prime[pp]:
          ans = composite[cp]
          cp += 1
        else:
          ans = prime[pp]
          pp += 1
      else:
        ans = prime[pp+n-i]
        break
    print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
 
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
 
 
class Prime():
    def __init__(self, m):
        self.M = m + 1
        self.A = a = [True] * self.M
        a[0] = a[1] = 0
        self.T = t = []
        sq = int(math.sqrt(self.M))
        q = 0
        for i in range(2, sq + 1):
            if not a[i]:
                a[i] = q
                continue
            t.append(i)
            a[i] = q
            q += 1
            for j in range(i*i,m,i):
                a[j] = False
 
        for i in range(sq + 1, self.M):
            if a[i]:
                a[i] = q
                q += 1
                t.append(i)
            else:
                a[i] = q
 
    def is_prime(self, n):
        return self.A[n]
 
 
def main():
    rr = []
 
    M = 7368792
    pr = Prime(M)
 
    def f(m, n):
        nn = n
        g = [None] * (m*m)
        for i in range(m, m*m):
            if not g[i]:
                if n == 0:
                    return i
                n -= 1
                for j in range(i, m*m, i):
                    g[j] = 1
        d = pr.A[m*m]
        return pr.T[d+n]
 
    while True:
        m,n = LI()
        if m == 0 and n == 0:
            break
        rr.append(f(m,n))
 
    return '\n'.join(map(str,rr))
 
 
 
 
print(main())

Submission status: Runtime Error

Solution code:
# AOJ 1610: Bamboo Blossoms
# Python3 2018.7.13 bal4u

MAX = 7368792
cno = 0
tbl = [0]*MAX
while True:
	m, n = map(int, input().split())
	if m == 0: break
	cno += 1
	for i in range(n):
		for j in range(m, MAX, m): tbl[j] = cno;
		for j in range(m, MAX):
			if tbl[j] != cno: break
			m += 1
	print(m)

Submission status: Runtime Error

Solution code:
# AOJ 1610: Bamboo Blossoms
# Python3 2018.7.13 bal4u

MAX = 7368792
cno = 0
tbl = [0]*(MAX+2)
while True:
	m, n = map(int, input().split())
	if m == 0: break
	cno += 1
	for i in range(n):
		for j in range(m, MAX, m): tbl[j] = cno;
		for j in range(m, MAX):
			if tbl[j] != cno: break
			m += 1
	print(m)

Submission status: Runtime Error

Solution code:
# AOJ 1610: Bamboo Blossoms
# Python3 2018.7.13 bal4u

MAX = 7368792
cno = 0
tbl = [0]*(MAX+2)
while True:
	m, n = map(int, input().split())
	if m == 0: break
	tbl = [0] * (MAX+1)
	for i in range(n):
		for j in range(m, MAX, m): tbl[j] = 1
		k = m
		for j in range(m, MAX):
			if not tbl[j]: break
			k += 1
		m = k
	print(m)

Submission status: Runtime Error

Solution code:
while 1:
    m, n = map(int, raw_input().split())
    if m == 0:
        break
    MAX = 10**7
    p= [0]*(MAX+1)
    i = m
    cnt = 0
    while 1:
        if not p[i]:
            if cnt == n:
                break
            for j in xrange(i, MAX, i):
                p[j] = 1
            cnt += 1
        i += 1
    print i

Submission status: Runtime Error

Solution code:
MAX = 10**7
p = [0]*(MAX+1)
t = 1
while 1:
    m, n = map(int, raw_input().split())
    if m == 0:
        break
    i = m
    cnt = 0
    while 1:
        if p[i] != t:
            if cnt == n:
                break
            for j in xrange(i, MAX, i):
                p[j] = t
            cnt += 1
        i += 1
    print i
    t += 1

Submission status: Runtime Error

Solution code:
import math
MAX = 7400000
prime = [1]*MAX
prime[0] = prime[1] = 0
res = []
sq = int(math.sqrt(MAX))
for i in xrange(2, sq+1):
    q = len(res)
    if prime[i]:
        res.append(i)
        for j in xrange(i*i, MAX, i):
            prime[j] = 0
    prime[i] = q
for i in xrange(sq+1, MAX):
    q = len(res)
    if prime[i]:
        res.append(i)
    prime[i] = q

def solve(m, n):
    # [m,m*m)
    sat = [0]*(m*m)
    for i in xrange(m, m*m):
        if not sat[i]:
            if n == 0:
                return i
            n -= 1
            for j in xrange(i, m*m, i):
                sat[j] = 1
    # [m*m,\inf)
    idx = prime[m*m]
    print m*m, res[idx]
    return res[idx+n]
while 1:
    m, n = map(int, raw_input().split())
    print solve(m, n)

Submission status: Runtime Error

Solution code:
MAX = 10**7
p = [0]*(MAX+1)
t = 1
while 1:
    m, n = map(int, raw_input().split())
    if m == 0:
        break
    i = m
    cnt = 0
    while 1:
        if p[i] != t:
            if cnt == n:
                break
            j = i
            while j < MAX:
                p[j] = t
                j += i
            cnt += 1
        i += 1
    print i
    t += 1

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if n==0:break
    a=[0]*7368792
    b,c=m,0
    while c!=n:
        if a[b]==0:
            i=1
            c+=1
            while i*b<7368792:
                a[i*b]=1
                i+=1
        b+=1
    while a[b]:b+=1
    print(b)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a=[0]*7368792
    b,c=m,0
    while c!=n:
        if a[b]==0:
            i=1
            c+=1
            while i*b<7368792:
                a[i*b]=1
                i+=1
        b+=1
    while a[b]:b+=1
    print(b)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==n==0:break
    a=[0]*7368792
    b,c=m,0
    while c!=n:
        if a[b]==0:
            i=1
            c+=1
            while i*b<7368792:
                a[i*b]=1
                i+=1
        b+=1
    while a[b]:b+=1
    print(b)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==n==0:break
    a=[0]*18368792
    b,c=m,0
    while c!=n:
        if a[b]==0:
            i=1
            c+=1
            while i*b<7368792:
                a[i*b]=1
                i+=1
        b+=1
    while a[b]:b+=1
    print(b)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a=[0]*7368792
    b=m
    while 1:
        if not a[b]:
            if n==0: 
                print(b)
                break
            n-=1
            for i in range(b,7368792,b):
                a[i]=1
        b+=1

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a=[0]*7400000
    b=m
    while 1:
        if 0==a[b]:
            if n==0:
                print(b)
                break
            n-=1
            for i in range(b,7368792,b):a[i]=1
        b+=1

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a=[True]*7400000
    while 1:
        if a[m]:
            if n==0:
                print(m)
                break
            n-=1
            for i in range(m*2,7368792,m):a[i]=False
        m+=1

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if n==0:break
    a=[False]*7400000
    while n:
        while a[m]:m+=1     
        n-=1
        for i in range(m,7368792,m):a[i]=True
    while a[m]:m+=1
    print(m)

Submission status: Runtime Error

Solution code:
while 1:
    m,n=map(int,input().split())
    if n==m==0:break
    a=[False]*7400000
    while n:
        while a[m]:m+=1     
        n-=1
        for i in range(m,7368792,m):a[i]=True
    while a[m]:m+=1
    print(m)

Submission status: Runtime Error

Solution code:
while True:
    M, N = map(int, input().split())
    if M == N == 0:
        break
    INF = 7368791
    P = [False] * (INF + 1)
    cnt = 0
    for i in range(M, INF + 1):
        if cnt >= N:
            break
        if not P[i]:
            for j in range(i, INF + 1, i):
                P[j] = True
            cnt += 1
    for i in range(M, INF + 1):
        if not P[i]:
            print(i)
            break

Submission status: Runtime Error

Solution code:
memo = dict()
while True:
    M, N = map(int, input().split())
    if M == N == 0:
        break
    if (M, N) in memo:
        print(memo[(M, N)])
        continue
    INF = 7368791
    P = [False] * (INF + 1)
    cnt = 0
    for i in range(M, INF + 1):
        if cnt >= N:
            break
        if not P[i]:
            memo[(M, cnt)] = i
            for j in range(i, INF + 1, i):
                P[j] = True
            cnt += 1
    for i in range(M, INF + 1):
        if not P[i]:
            memo[(M, N)] = i
            print(i)
            break

Submission status: Runtime Error

Solution code:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
memo = dict()
while True:
    M, N = map(int, input().split())
    if M == N == 0:
        break
    if (M, N) in memo:
        print(memo[(M, N)])
        continue
    INF = 7368791
    P = [False] * (INF + 1)
    cnt = 0
    for i in range(M, INF + 1):
        if cnt >= N:
            break
        if not P[i]:
            memo[(M, cnt)] = i
            for j in range(i, INF + 1, i):
                P[j] = True
            cnt += 1
    for i in range(M, INF + 1):
        if not P[i]:
            memo[(M, N)] = i
            print(i)
            break

Submission status: Runtime Error

Solution code:
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input
memo = dict()
INF = 7368791
P = [False] * (INF + 1)
while True:
    M, N = map(int, input().split())
    if M == N == 0:
        break
    if (M, N) in memo:
        print(memo[(M, N)])
        continue
    for i in range(INF + 1):
        P[i] = False
    cnt = 0
    for i in range(M, INF + 1):
        if cnt >= N:
            break
        if not P[i]:
            memo[(M, cnt)] = i
            for j in range(i, INF + 1, i):
                P[j] = True
            cnt += 1
    for i in range(M, INF + 1):
        if not P[i]:
            memo[(M, N)] = i
            print(i)
            break

Submission status: Runtime Error

Solution code:
MAX = 7368800

while True:
    M,N = map(int,input().split())
    if M == 0: break
    sieve = [0,0] + [1]*MAX
    m = M
    cnt = 0
    while True:
        if sieve[m]:
            if cnt < N:
                cnt += 1
                for n in range(2*m,MAX+1,m):
                    sieve[n] = 0
            else:
                print(m)
                break
        m += 1

Submission status: Runtime Error

Solution code:
MAX = 7368800

src = [[] for i in range(101)]
i = 0
while True:
    m,n = map(int,input().split())
    if m == 0: break
    src[m].append((n,i))
    i += 1
Q = i

ans = [None] * Q
for m,qs in enumerate(src):
    if len(qs) == 0: continue
    qs.sort()
    sieve = [0,0] + [1]*MAX
    maxn = qs[-1][0]
    tmp = []
    n = m
    while len(tmp) <= maxn:
        if sieve[n]:
            tmp.append(n)
            for nn in range(2*n,MAX+1,n):
                sieve[nn] = 0
        n += 1
    for n,i in qs:
        ans[i] = tmp[n]

for a in ans:
    print(a)

Submission status: Runtime Error

Solution code:
MAX = 7368800

src = [[] for i in range(101)]
i = 0
while True:
    m,n = map(int,input().split())
    if m == 0: break
    src[m].append((n,i))
    i += 1
Q = i

ans = [None] * Q
for m,qs in enumerate(src):
    if len(qs) == 0: continue
    qs.sort()
    sieve = [0,0] + [1]*MAX
    maxn = qs[-1][0]
    tmp = []
    n = m
    while len(tmp) <= maxn:
        if sieve[n]:
            tmp.append(n)
            for nn in range(2*n,min(maxn*15,MAX+1),n):
                sieve[nn] = 0
        n += 1
    for n,i in qs:
        ans[i] = tmp[n]

for a in ans:
    print(a)

Submission status: Runtime Error

Solution code:
while(True):
    a = list(map(int, input().split()))
    m , n = a[0], a[1]
    if m == 0:
        break
    lis = [i for i in range(m,n * 16)]
    for i in range(n):
        lis = [i for i in lis if i % lis[0]]
    print(lis[0])

Submission status: Runtime Error

Solution code:
def main():
    a = list(map(int, input().split()))
    m , n = a[0], a[1]
    if m == 0:
        return 1
    print(sieve(m,n)[0])
    return 0

def mark(s, x):
    for i in range(x, len(s), x):
        s[i] = False

def sieve(m,n):
    s = [False] * m + [True] * 16 * n
    count = 0
    for x in range(m,n * 16):
        if s[x]:
            mark(s, x)
            count += 1
            if count == n:
                break
    return [i for i in range(len(s)) if s[i] and i > 1]

while(True):
    if main():
        break

Submission status: Runtime Error

Solution code:
def main():
    a = list(map(int, input().split()))
    m , n = a[0], a[1]
    if m == 0:
        return 1
    print(sieve(m,n)[0])
    return 0

def mark(s, x):
    for i in range(x, len(s), x):
        s[i] = False

def sieve(m,n):
    s = [False] * m + [True] * 16 * n
    count = 0
    for x in range(m,n * 8):
        if s[x]:
            mark(s, x)
            count += 1
            if count == n:
                break
    return [i for i in range(len(s)) if s[i] and i > 1]

while(True):
    if main():
        break

Submission status: Runtime Error

Solution code:
def mark(s, x):
    for i in range(x, len(s), x):
        s[i] = False

def sieve(m,n):
    s = [False] * m + [True] * 16 * n
    count = 0
    for x in range(m,n * 16):
        if s[x]:
            mark(s, x)
            count += 1
            if count == n:
                break
    return [i for i in range(len(s)) if s[i] and i > 1]

while(True):
    a = list(map(int, input().split()))
    m , n = a[0], a[1]
    if m == 0:
        break
    print(sieve(m,n)[0])

Submission status: Runtime Error

Solution code:
def mark(s, x):
    for i in range(x, len(s), x):
        s[i] = False

def sieve(m,n):
    s = [False] * m + [True] * 16 * n
    count = 0
    for x in range(m,n * 16):
        if s[x]:
            mark(s, x)
            count += 1
            if count == n:
                break
    return [i for i in range(len(s)) if s[i] and i > 1]

def main():

    while(True):
        a = list(map(int, input().split()))
        m , n = a[0], a[1]
        if m == 0:
            return(0)
        print(sieve(m,n)[0])

main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)
def f(start, goal):
	global C
	for i in range(start, goal):
		for j in range(m, (i//2)+1):
			if (i%j == 0):
				C += 1
				f(i+1, C)
				
while 1:
	m, n = map(int, input().split())
	if (m == 0 and n == 0):
		break;
	if (n < m):
		print(m + n)
	elif (n == m):
		print(m + n + 1)
	else:
		C = m+n+1
		f(2*m, C)
		c = int(C)
		while 1:
			for i in range(m, C):
				if (c%i == 0):
					break
			else:
				print(c)
				break
			c += 1

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        m,n = LI()
        if n == 0 and m == 0:
            break

        l = 7368792
        a = [None] * l
        j = m
        for i in range(n):
            while not a[j] is None:
                j += 1
            for k in range(j,l,j):
                a[k] = 1
        while not a[j] is None:
            j += 1

        rr.append(j)

    return '\n'.join(map(str, rr))


print(main())

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        m,n = LI()
        if n == 0 and m == 0:
            break

        l = 7368792
        a = [None] * l
        j = m
        for i in range(n):
            while a[j]:
                j += 1
            for k in range(j,l,j):
                a[k] = True
        while a[j]:
            j += 1

        print(j)

    return


main()

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        m,n = LI()
        if n == 0 and m == 0:
            break

        l = min(7368792,n*20)
        a = [None] * l
        j = m
        for i in range(n):
            while a[j]:
                j += 1
            for k in range(j,l,j):
                a[k] = True
        while a[j]:
            j += 1

        print(j)

    return


main()

Submission status: Runtime Error

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        m,n = LI()
        if n == 0 and m == 0:
            break

        l = 8368792
        a = [None] * l
        j = m
        for i in range(n):
            while a[j]:
                j += 1
            for k in range(j,l,j):
                a[k] = True
        while a[j]:
            j += 1

        print(j)

    return


main()

Submission status: Runtime Error

Solution code:
while True:
    m, n = map(int,input().split())
    if m == 0 and n == 0:
        break
    den = [m]
    for i in range(m+1, 1000000, 1):
        den.append(i)
        for j in range(0, len(den)-1, 1):
            if i%den[j] == 0:
                den.remove(i)
                break
        if len(den) > n:
            print(den[-1])
            break

Submission status: Runtime Error

Solution code:
while True:
    (n, m) = list(map(int, input().split()))
    if n == 0:
        break
    arr = [n]
    app = arr.append
    arrsize = 1
    i = n + 1
    while True:
        ge = True
        for e in arr:
            if i % e == 0:
                ge = False
                break
        if ge:
            app(i)
            arrsize += 1
            if arrsize > m:
                print(i)
                break
        i += 1

Submission status: Runtime Error

Solution code:
while True:
    m, n = map(int,input().split())
    if m == 0 and n == 0:
        break
    sea = []
    pri = []
    for i in range(m, 7368792):
        sea.append(True)
    for i in range(0, m):
        sea[i] = False
    for i in range(m, len(sea)):
        if sea[i] == True:
            pri.append(i)
            if len(pri) > n:
                print(pri[-1])
                break
            for j in range(i, len(sea), i):
                sea[j] = False

Submission status: Runtime Error

Solution code:
while True:
    m, n = map(int,input().split())
    if m == 0 and n == 0:
        break
    sea = list()
    pri = list()
    for i in range(m, 7368792):
        sea.append(True)
        #print(sea)
    for i in range(0, m):
        sea[i] = False
    for i in range(m, len(sea)):
        if sea[i] == True:
            pri.append(i)
            if len(pri) > n:
                print(pri[-1])
                break
            for j in range(i, len(sea), i):
                sea[j] = False