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

Solution (Python):
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())

Solution (Python):
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):
    
    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
    
    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)

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
from bisect import bisect_left

def rwh_primes2(n):
    
    """ 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)

Solution (Python):
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())