Problem:
 Score: 400 points    Problem Statement  Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions:   a_i  (1 \leq i \leq N) is a prime number at most 55  555 .  The values of a_1, a_2, ..., a_N are all different.  In every choice of five different integers from a_1, a_2, ..., a_N , the sum of those integers is a composite number.   If there are multiple such sequences, printing any of them is accepted.      Notes  An integer N not less than 2 is called a prime number if it cannot be divided evenly by any integers except 1 and N , and called a composite number otherwise.      Constraints   N is an integer between 5 and 55 (inclusive).         Input  Input is given from Standard Input in the following format:  N       Output  Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.        Sample Input 1 5      Sample Output 1 3 5 7 11 31  Let us see if this output actually satisfies the conditions. First, 3 , 5 , 7 , 11 and 31 are all different, and all of them are prime numbers. The only way to choose five among them is to choose all of them, whose sum is a_1+a_2+a_3+a_4+a_5=57 , which is a composite number. There are also other possible outputs, such as 2 3 5 7 13 , 11 13 17 19 31 and 7 11 5 31 3 .       Sample Input 2 6      Sample Output 2 2 3 5 7 11 13   2 , 3 , 5 , 7 , 11 , 13 are all different prime numbers.  2+3+5+7+11=28 is a composite number.  2+3+5+7+13=30 is a composite number.  2+3+5+11+13=34 is a composite number.  2+3+7+11+13=36 is a composite number.  2+5+7+11+13=38 is a composite number.  3+5+7+11+13=39 is a composite number.   Thus, the sequence 2 3 5 7 11 13 satisfies the conditions.       Sample Input 3 8      Sample Output 3 2 5 7 13 19 37 67 79

Solution (Python):













table5 = [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381, 1451, 1471, 1481, 1511, 1531, 1571, 1601, 1621, 1721, 1741, 1801, 1811, 1831, 1861, 1871, 1901, 1931, 1951, 2011, 2081, 2111, 2131, 2141, 2161, 2221, 2251, 2281, 2311, 2341, 2351, 2371, 2381, 2411, 2441, 2521, 2531, 2551, 2591, 2621, 2671, 2711, 2731, 2741, 2791, 2801, 2851, 2861, 2971, 3001, 3011, 3041, 3061, 3121, 3181, 3191, 3221, 3251, 3271, 3301, 3331, 3361, 3371, 3391, 3461, 3491, 3511, 3541, 3571, 3581, 3631, 3671, 3691, 3701, 3761, 3821, 3851, 3881, 3911, 3931, 4001, 4021, 4051, 4091, 4111, 4201, 4211, 4231, 4241, 4261, 4271, 4391, 4421, 4441, 4451, 4481, 4561, 4591, 4621, 4651, 4691, 4721, 4751, 4801, 4831, 4861, 4871, 4931, 4951, 5011, 5021, 5051, 5081, 5101, 5171, 5231, 5261, 5281, 5351, 5381, 5431, 5441, 5471, 5501, 5521, 5531, 5581, 5591, 5641, 5651, 5701, 5711, 5741, 5791, 5801, 5821, 5851, 5861, 5881, 5981, 6011, 6091, 6101, 6121, 6131, 6151, 6211, 6221, 6271, 6301, 6311, 6361, 6421, 6451, 6481, 6491, 6521, 6551, 6571, 6581, 6661, 6691, 6701, 6761, 6781, 6791, 6841, 6871, 6911, 6961, 6971, 6991, 7001, 7121, 7151, 7211, 7321, 7331, 7351, 7411, 7451, 7481, 7541, 7561, 7591, 7621, 7681, 7691, 7741, 7841, 7901, 7951, 8011, 8081, 8101, 8111, 8161, 8171, 8191, 8221, 8231, 8291, 8311, 8431, 8461, 8501, 8521, 8581, 8641, 8681, 8731, 8741, 8761, 8821, 8831, 8861, 8941, 8951, 8971, 9001, 9011, 9041, 9091, 9151, 9161, 9181, 9221, 9241, 9281, 9311, 9341, 9371, 9391, 9421, 9431, 9461, 9491, 9511, 9521, 9551, 9601, 9631, 9661, 9721, 9781, 9791, 9811, 9851, 9871, 9901, 9931, 9941, 10061, 10091, 10111, 10141, 10151, 10181, 10211, 10271, 10301, 10321, 10331, 10391, 10501, 10531, 10601, 10631, 10651, 10691, 10711, 10771, 10781, 10831, 10861, 10891, 11071, 11131, 11161, 11171, 11251, 11261, 11311, 11321, 11351, 11411, 11471, 11491, 11551, 11621, 11681, 11701, 11731, 11801, 11821, 11831, 11941, 11971, 11981, 12011, 12041, 12071, 12101, 12161, 12211, 12241, 12251, 12281, 12301, 12391, 12401, 12421, 12451, 12491, 12511, 12541, 12601, 12611, 12641, 12671, 12721, 12781, 12791, 12821, 12841, 12911, 12941, 13001, 13121, 13151, 13171, 13241, 13291, 13331, 13381, 13411, 13421, 13441, 13451, 13591, 13681, 13691, 13711, 13721, 13751, 13781, 13831, 13841, 13901, 13921, 13931, 14011, 14051, 14071, 14081, 14221, 14251, 14281, 14321, 14341, 14401, 14411, 14431, 14461, 14551, 14561, 14591, 14621, 14731, 14741, 14771, 14821, 14831, 14851, 14891, 14951, 15031, 15061, 15091, 15101, 15121, 15131, 15161, 15241, 15271, 15331, 15361, 15391, 15401, 15451, 15461, 15511, 15541, 15551, 15581, 15601, 15641, 15661, 15671, 15731, 15761, 15791, 15881, 15901, 15971, 15991, 16001, 16061, 16091, 16111, 16141, 16231, 16301, 16361, 16381, 16411, 16421, 16451, 16481, 16561, 16631, 16651, 16661, 16691, 16741, 16811, 16831, 16871, 16901, 16921, 16931, 16981, 17011, 17021, 17041, 17191, 17231, 17291, 17321, 17341, 17351, 17401, 17431, 17471, 17491, 17551, 17581, 17681, 17761, 17791, 17851, 17881, 17891, 17911, 17921, 17971, 17981, 18041, 18061, 18121, 18131, 18181, 18191, 18211, 18251, 18301, 18311, 18341, 18371, 18401, 18451, 18461, 18481, 18521, 18541, 18661, 18671, 18691, 18701, 18731, 18911, 19001, 19031, 19051, 19081, 19121, 19141, 19181, 19211, 19231, 19301, 19381, 19391, 19421, 19441, 19471, 19501, 19531, 19541, 19571, 19661, 19681, 19751, 19801, 19841, 19861, 19891, 19961, 19991, 20011, 20021, 20051, 20071, 20101, 20161, 20201, 20231, 20261, 20341, 20411, 20431, 20441, 20521, 20551, 20611, 20641, 20681, 20731, 20771, 20921, 20981, 21001, 21011, 21031, 21061, 21101, 21121, 21191, 21211, 21221, 21341, 21391, 21401, 21481, 21491, 21521, 21601, 21611, 21661, 21701, 21751, 21821, 21841, 21851, 21871, 21881, 21911, 21961, 21991, 22031, 22051, 22091, 22111, 22171, 22271, 22291, 22381, 22391, 22441, 22481, 22501, 22511, 22531, 22541, 22571, 22621, 22651, 22691, 22721, 22741, 22751, 22811, 22861, 22871, 22901, 22921, 22961, 23011, 23021, 23041, 23071, 23081, 23131, 23201, 23251, 23291, 23311, 23321, 23371, 23431, 23531, 23561, 23581, 23671, 23741, 23761, 23801, 23831, 23911, 23971, 23981, 24001, 24061, 24071, 24091, 24121, 24151, 24181, 24251, 24281, 24371, 24391, 24421, 24481, 24551, 24571, 24611, 24631, 24671, 24691, 24781, 24821, 24841, 24851, 24971, 25031, 25111, 25121, 25171, 25261, 25301, 25321, 25391, 25411, 25471, 25541, 25561, 25601, 25621, 25741, 25771, 25801, 25841, 25931, 25951, 25981, 26021, 26041, 26111, 26141, 26161, 26171, 26251, 26261, 26321, 26371, 26431, 26501, 26561, 26591, 26641, 26681, 26701, 26711, 26731, 26801, 26821, 26861, 26881, 26891, 26921, 26951, 26981, 27011, 27031, 27061, 27091, 27191, 27211, 27241, 27271, 27281, 27361, 27431, 27481, 27541, 27551, 27581, 27611, 27631, 27691, 27701, 27751, 27791, 27851, 27901, 27941, 27961, 28001, 28031, 28051, 28081, 28111, 28151, 28181, 28201, 28211, 28351, 28411, 28541, 28571, 28591, 28621, 28631, 28661, 28711, 28751, 28771, 28871, 28901, 28921, 28961, 29021, 29101, 29131, 29191, 29201, 29221, 29231, 29251, 29311, 29401, 29411, 29501, 29531, 29581, 29611, 29641, 29671, 29741, 29761, 29851, 29881, 29921, 30011, 30071, 30091, 30161, 30181, 30211, 30241, 30271, 30341, 30391, 30431, 30491, 30631, 30661, 30671, 30781, 30841, 30851, 30871, 30881, 30911, 30931, 30941, 30971, 31051, 31081, 31091, 31121, 31151, 31181, 31231, 31271, 31321, 31391, 31481, 31511, 31531, 31541, 31601, 31721, 31741, 31751, 31771, 31891, 31981, 31991, 32051, 32141, 32191, 32251, 32261, 32321, 32341, 32371, 32381, 32401, 32411, 32441, 32491, 32531, 32561, 32611, 32621, 32771, 32801, 32831, 32911, 32941, 32971, 33071, 33091, 33151, 33161, 33181, 33191, 33211, 33301, 33311, 33331, 33391, 33461, 33521, 33581, 33601, 33641, 33721, 33751, 33791, 33811, 33851, 33871, 33911, 33931, 33941, 33961, 34031, 34061, 34141, 34171, 34211, 34231, 34261, 34301, 34351, 34361, 34381, 34421, 34471, 34501, 34511, 34591, 34631, 34651, 34721, 34781, 34841, 34871, 34961, 34981, 35051, 35081, 35111, 35141, 35171, 35201, 35221, 35251, 35281, 35291, 35311, 35381, 35401, 35461, 35491, 35521, 35531, 35591, 35671, 35731, 35771, 35801, 35831, 35851, 35911, 35951, 36011, 36061, 36131, 36151, 36161, 36191, 36241, 36251, 36341, 36451, 36541, 36551, 36571, 36671, 36691, 36721, 36761, 36781, 36791, 36821, 36871, 36901, 36931, 37021, 37061, 37171, 37181, 37201, 37321, 37361, 37441, 37501, 37511, 37561, 37571, 37591, 37691, 37781, 37811, 37831, 37861, 37871, 37951, 37991, 38011, 38201, 38231, 38261, 38281, 38321, 38351, 38371, 38431, 38461, 38501, 38561, 38611, 38651, 38671, 38711, 38791, 38821, 38851, 38861, 38891, 38921, 38971, 39041, 39161, 39181, 39191, 39241, 39251, 39301, 39341, 39371, 39451, 39461, 39511, 39521, 39541, 39551, 39581, 39631, 39671, 39761, 39791, 39821, 39841, 39901, 39971, 40031, 40111, 40151, 40231, 40241, 40351, 40361, 40471, 40531, 40591, 40751, 40771, 40801, 40841, 40961, 41011, 41051, 41081, 41131, 41141, 41161, 41201, 41221, 41231, 41281, 41341, 41351, 41381, 41411, 41491, 41521, 41611, 41621, 41641, 41651, 41681, 41761, 41771, 41801, 41851, 41911, 41941, 41981, 42061, 42071, 42101, 42131, 42181, 42221, 42281, 42331, 42391, 42451, 42461, 42491, 42571, 42611, 42641, 42701, 42751, 42821, 42841, 42901, 42961, 43051, 43151, 43201, 43261, 43271, 43291, 43321, 43331, 43391, 43411, 43441, 43451, 43481, 43541, 43591, 43651, 43661, 43691, 43711, 43721, 43781, 43801, 43891, 43951, 43961, 43991, 44021, 44041, 44071, 44101, 44111, 44131, 44171, 44201, 44221, 44281, 44351, 44371, 44381, 44491, 44501, 44531, 44621, 44641, 44651, 44701, 44711, 44741, 44771, 44851, 44971, 45061, 45121, 45131, 45161, 45181, 45191, 45281, 45341, 45361, 45481, 45491, 45541, 45631, 45641, 45691, 45751, 45821, 45841, 45971, 46021, 46051, 46061, 46091, 46141, 46171, 46181, 46261, 46271, 46301, 46351, 46381, 46411, 46441, 46451, 46471, 46511, 46591, 46601, 46681, 46691, 46751, 46771, 46811, 46831, 46861, 46901, 47041, 47051, 47111, 47161, 47221, 47251, 47351, 47381, 47431, 47441, 47491, 47501, 47521, 47581, 47591, 47681, 47701, 47711, 47741, 47791, 47881, 47911, 47951, 47981, 48091, 48121, 48131, 48221, 48271, 48281, 48311, 48341, 48371, 48481, 48491, 48541, 48571, 48611, 48661, 48731, 48751, 48761, 48781, 48821, 48871, 48991, 49031, 49081, 49121, 49171, 49201, 49211, 49261, 49331, 49391, 49411, 49451, 49481, 49531, 49681, 49711, 49741, 49801, 49811, 49831, 49871, 49891, 49921, 49991, 50021, 50051, 50101, 50111, 50131, 50221, 50231, 50261, 50291, 50311, 50321, 50341, 50411, 50441, 50461, 50551, 50581, 50591, 50651, 50671, 50741, 50821, 50891, 50951, 50971, 51001, 51031, 51061, 51071, 51131, 51151, 51241, 51341, 51361, 51421, 51431, 51461, 51481, 51511, 51521, 51551, 51581, 51631, 51691, 51721, 51871, 51941, 51971, 51991, 52021, 52051, 52081, 52121, 52181, 52201, 52291, 52301, 52321, 52361, 52391, 52501, 52511, 52541, 52561, 52571, 52631, 52691, 52711, 52721, 52861, 52901, 52951, 52981, 53051, 53101, 53161, 53171, 53201, 53231, 53281, 53381, 53401, 53411, 53441, 53551, 53591, 53611, 53681, 53731, 53791, 53831, 53861, 53881, 53891, 53951, 54001, 54011, 54091, 54101, 54121, 54151, 54181, 54251, 54311, 54331, 54361, 54371, 54401, 54421, 54521, 54541, 54581, 54601, 54631, 54721, 54751, 54851, 54881, 54941, 55001, 55021, 55051, 55061, 55171, 55201, 55291, 55331, 55351, 55381, 55411, 55441, 55501, 55511, 55541]

N = int(input())
print(*table5[:N])

Solution (Python):
import math
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
s=[]
n=int(input())
for i in range(2,55555):
    if is_prime(i)==True:
        if i%5==1:
            s.append(i)
print(' '.join(map(str, s[:n])))

Solution (Python):
N=int(input())
import math
def primes(x):
  if x < 2: return []
  primes = [i for i in range(x)]
  primes[1] = 0 

    
  for prime in primes:
    if prime > math.sqrt(x): break
    if prime == 0: continue
    for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

  return [prime for prime in primes if prime != 0]

A=primes(55555)
B=[]
cnt=0
for i in A:
  if i%5==1:
    B.append(i)
    cnt+=1
    if cnt==N:
      print(*B)
      exit()

Solution (Python):

n = int(input())
j = 0
data = [0] * n
i = 2
while j < n:
    divcnt = 0
    for k in range(1, i * 5 + 2):
        if (i * 5 + 1) % k == 0:
            divcnt += 1
        
    if divcnt == 2:
        data[j] = i * 5 + 1
        j += 1
    
    i += 1
    
for i in range(n):
    print("{0} ".format(data[i]), end = "")

Solution (Python):
import math
def prime(n):
    max=int(math.sqrt(n))
    li=[i for i in range(2,n+1)]
    primes=[]
    while li[0]<=max:
        primes.append(li[0])
        tmp=li[0]
        li=[i for i in li if i%tmp!=0]
    primes.extend(li)
    return primes
N=int(input())
li=[i for i in prime(1382) if i%5==1]
print(*li[:N])

Solution (Python):
import sys
input = sys.stdin.readline
INF = 10**9
MOD = 10**9 + 7

def sieve(n):
    prime=[]
    limit=n**0.5
    data=[i+1 for i in range(1,n)]
    while True:
        p=data[0]
        if limit<=p:
            return prime+data
        prime.append(p)
        data=[e for e in data if e%p!=0]
   
primes = sieve(55556)

def main():
   n = int(input())
   
   ans = []
   for p in primes:
      if p%5 == 1:
         ans.append(p)
         if len(ans) == n:
            break
   
   print(*ans)
   
if __name__=='__main__':
    main()

Solution (Python):
def eratosthenes(n):
    prime = [2]
    if n == 2:
        return prime
    limit = int(n ** 0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


def solve():
    N = int(input())
    primes = eratosthenes(55555)
    ans = []
    for p in primes:
        if p % 5 == 1:
            ans.append(p)
    print(' '.join(map(str, ans[:N])))


if __name__ == '__main__':
    solve()

Solution (Python):
def sieve(n):
  ass = []
  is_prime = [True]*(n+1)
  is_prime[0] = False
  is_prime[1] = False

  for i in range(2, int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2, n+1, i):
      is_prime[j] = False
  for i in range(n+1):
    if is_prime[i]:
      ass.append(i)
  return(ass)

l = sieve(55600)
l = [i for i in l if i%5 ==1]
n = int(input())

print(*l[0:n])

Solution (Python):
def sieve(n):
  ass = []
  is_prime = [True]*(n+1)
  is_prime[0] = False
  is_prime[1] = False

  for i in range(2, int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2, n+1, i):
      is_prime[j] = False
  for i in range(n+1):
    if is_prime[i]:
      ass.append(i)
  return(ass)

l = sieve(55600)
l = [i for i in l if i%5 ==1]
n = int(input())

print(*l[0:n])

Solution (Python):
def the_sieve_of_eratosthenes(i):
    s = [j for j in range(2, i + 1)]
    j = 0
    while True:
        if j >= i - 3:
            for k in range(len(s) - 1, 0, -1):
                if s[k] == 0:
                    del s[k]
            return s
        if s[j] != 0:
            for k in range(2 * s[j] - 2, i - 1, s[j]):
                s[k] = 0
        j += 1

n = int(input())
p = the_sieve_of_eratosthenes(55555)
ans = []
i = 0
for _ in range(n):
    while True:
        if p[i] % 10 == 1:
            ans.append(p[i])
            i += 1
            break
        i += 1
print(" ".join(map(str, ans)))

Solution (Python):
N = int(input())

def is_prime(n):
  if n == 1:
    return False
  for i in range(2,int(n**0.5)+1):
    if n % i == 0:
      return False
  return True

p = []
for i in range(2, 55555+1):
  if is_prime(i) and i % 5 == 1:
    p.append(i)

print(*p[:N])

Solution (Python):
print(*[11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381][:int(input())])

Solution (Python):

def is_prime(n):
    if n <= 1:
        return False
    if n == 2:
        return True
    i = 2
    while i*i <= n:
        if n % i == 0:
            return False
        i += 1
    return True

def Eratosthenes_sieve(n):
    table = [True]*(n+1)
    for i in range(n+1):
        if is_prime(i):
            for j in range(2*i,n+1,i): 
                table[j] = False
        else:
            table[i] = False
    return table

a = 55555
t = Eratosthenes_sieve(a)

N = int(input())
ans = []
for i in range(1,55556,5):
    if t[i]:
        ans.append(i)
ans = ans[:N]
print(*ans)

Solution (Python):
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
prime = primes(55555)

N = int(input())




ans = []
for p in prime:
    if p % 5 == 1:
        ans.append(p)
    if len(ans) == N:
        break

print(*ans)

Solution (Python):
def main():
    N = int(input())

    def Eratosthenes(x: int):
        import math
        sup = int(x)
        primes = {i for i in range(2, sup+1)}
        for i in range(2, int(math.sqrt(sup+1))+1):
            if i in primes:
                mul = 2
                while i*mul <= sup:
                    primes.discard(i*mul)
                    mul += 1
        return [p for p in primes if p % 5 == 1]

    primes = Eratosthenes(55555)
    
    from itertools import combinations
    for ps in combinations(primes, N):
        
        return print(*ps)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

def isPrime(i):
    if i == 2: return True
    k = 2
    while k ** 2 <= i:
        if i % k == 0: return False
        k += 1
    return True
            
def solve():
    input = sys.stdin.readline
    N = int(input())
    count = 0
    k = 1
    Ans = []
    while count < N:
        if isPrime(5 * k + 1):
            Ans.append(5 * k + 1)
            count += 1
        k += 1
    print(" ".join(map(str, Ans)))
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
N = int(input())


def eratosthenes_sieve(n):
    if n < 2:
        return []

    is_primes = [True] * (n + 1)
    for x in range(2, int(n ** 0.5 + 1) + 1):
        if is_primes[x]:
            for mx in range(2 * x, n + 1, x):
                is_primes[mx] = False

    return [i for i in range(2, n + 1) if is_primes[i]]


P = eratosthenes_sieve(55555)
P = [p for p in P if p % 5 == 1]
print(' '.join(map(str, P[:N])))

Solution (Python):
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    P = []
    B = [True] * 56000
    for i in range(2, 55555):
        if B[i]:
            if i % 5 == 1:
                P.append(str(i))
            for j in range(56000 // i):
                B[i * j] = False
    print(" ".join(P[: int(input())]))


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
ans = ["11"]
ans_len = 1
counter = 5
A = 55556
for i in range(31, A, 2):
    if ans_len == N:
        break
    if counter == 5:
        if all(i % j != 0 for j in prime):
            ans_len += 1
            ans.append(str(i))
        counter = 0
    prime.append(i)
    counter += 1

print(" ".join(ans))

Solution (Python):
def main():
    result = []
    counter = 0

    primes = [2]
    nominee = 3
    while counter < 55:
        is_prime = True
        for prime in primes:
            if nominee % prime == 0:
                is_prime = False
        if is_prime:
            primes.append(nominee)
            if nominee % 5 == 1:
                result.append(nominee)
                counter += 1
        nominee += 2
    
    print(*result[:int(input())])
    

main()

Solution (Python):
import math
n=int(input())
def chk(n):
  for i in range(2,int(math.sqrt(n))+1):
    if n%i==0:
      return False
  return True
ans=[]
for i in range(2,10000*1000+1):
  if chk(i) and i%5==1:
    ans.append(i)
  if len(ans)>=n:
    break
print(' '.join(map(str,ans)))

Solution (Python):
N = int(input())

def sieve(n):
    res = [True for _ in range(n + 1)]
    res[0] = False
    res[1] = False
    i = 2
    while i * i <= n:
        if res[i]:
            for j in range(i * 2, n + 1, i):
                res[j] = False
        i += 1
    return res

S = sieve(55555)
A = []
cnt = 0

for i in range(55555):
    if S[i] and i % 5 == 1:
        A.append(i)
        cnt += 1
    if cnt == N:
        break

print(*A)

Solution (Python):
from math import sqrt


def sieve(x):
    """
    Sieve of Eratosthenes
    :param x: max value
    :return: list of primes
    """

    primes = []
    li = list(range(2, x + 1))

    while li[0] <= sqrt(x):
        p = li[0]
        primes.append(p)
        li = [e for e in li if e % p != 0]

    primes += li
    return primes


n = int(input())

primes = sieve(55555)
mod5is1 = [e for e in primes if e % 5 == 1]
ans = mod5is1[:n]
print(*ans)

Solution (Python):
import math
N = int(input())
ans = []
ctr = 0





def is_prime(n):
	if n == 2: return True
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0: return False
	return True

for i in range(6, 55555 + 1, 5): 
	if is_prime(i):
		ans.append(i)
		ctr += 1
	if ctr == N: break
	
print(*ans)

Solution (Python):
import math


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


N = int(input())
primes = get_sieve_of_eratosthenes(55555)


primes = [x for x in primes if x % 5 == 1]
print(*primes[:N])

Solution (Python):
ans=[11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381, 1451]
n=int(input())
print(*ans[:n], sep=' ')

Solution (Python):
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

N = int(input())

primes = []
mod = 1
count = 0
for i in range(2,55555+1):
    if i%5 == mod and is_prime(i):
        primes.append(i)
        count += 1
    if count == N:
        break

print(*primes)

Solution (Python):
N=int(input())

a = 2
prime = [ 1 ] * 55559
prime[0] = 0
prime[1] = 0
while a < 55556:
  if prime[a] == 1:
    b = a + a
    while b < 55556:
      prime[b] = 0
      b += a
  a += 1
d = []
n = 0
for i in range(55556):
  if prime[i] == 1:
    if i%5==1:
      d.append(i)
      n += 1
      if n == N:
        break
      
for i in d:
  print(str(i)+" ", end="")
print("")

Solution (Python):
S = [19,29,59,79,89,109,139,149,179,199,229,269,349,359,379,389,409,419,439,449,479,499,509,569,599,619,659,709,719,739,769,809,829,839,859,919,929,1009,1019,1039,1049,1069,1109,1129,1229,1249,1259,1279,1289,1319,1459,1489,1499,1549,1559,1609,1619,1949,1999,2029]
N = int(input())

for i in range(N):
  print(S[i], end=" ")

Solution (Python):
import numpy as np
U = 55556
T = np.zeros(U)
T[2] = 1
T[3::2] = 1
for i in range(3,U,2):
  if i*i>U:
    break
  if T[i]:
    T[i*i::2*i] = 0
pls = np.where(T)[0]
N = int(input())
ans = []
for p in pls:
  if p%5==1:
    ans += [str(p)]
  if len(ans)==N:
    break
print(' '.join(ans))

Solution (Python):
L = [[] for i in range(5)]

for i in range(2,55556):
    D = 0
    for j in range(2,int(i**(1/2))+1):
        if i % j == 0:
            D = -1
            break
    if D == 0:
        L[i%5].append(i)





N = int(input())
print(" ".join(map(str,L[1][:N])))

Solution (Python):
N=int(input())
a=[11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 
761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]
print(*a[:N])

Solution (Python):





n = int(input())
primes = []


def isprime(x):
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
    return True


for i in range(2, 55555 + 1):
    if isprime(i) and str(i)[-1] == "1":
        primes.append(i)

print(" ".join(list(map(str, (primes[:n])))))

Solution (Python):
import math
def main():
    N = int(input())
    t = 1
    l = []
    while len(l) < N:
        x = t * 10 + 1
        d = int(math.sqrt(x))
        for i in range(2, d+1):
            if x % i == 0:
                break
        else:
            l.append(x)
        t += 1
    print(' '.join(str(i) for i in l))
main()

Solution (Python):
import itertools

n = int(input())

def Eratosthenes(n):
    Primes = [2]
    All = [x for x in range(3, n+1)]
    check = True
    max_check = int((n**(1/2)//1))
    while check:
        if All[0] > max_check:
            return Primes + All[1:]
        All = [x for x in All if x % Primes[-1] != 0]
        Primes.append(All[0])


Primes = Eratosthenes(55555)

Primes_select = [x for x in Primes if x % 5 == 1]
Ans = Primes_select[:n]
ans = [str(x) for x in Ans]
print(' '.join(ans))

Solution (Python):
def sieve(n):
    prime = [True] * (n+1)
    prime[0] = prime[1] = False
    for i in range(2, n+1):
        if prime[i]:
            for j in range(2*i, n+1, i):
                prime[j] = False
    return prime


MAX_A = 55555
is_prime = sieve(MAX_A)
N = int(input())
a = []
for i in range(MAX_A+1):
    if is_prime[i] and i % 5 == 1:
        a.append(str(i))
        if len(a) == N:
            break
print(' '.join(a))

Solution (Python):
def is_5mod1_prime(n):
    if n == 1:
        return False
    if n % 5 != 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


N = int(input())
primes = []
for i in range(55555):
    i += 1
    if is_5mod1_prime(i):
        primes.append(i)

ans = primes[:N]
print(' '.join([str(a) for a in ans]))

Solution (Python):
n = int(input())
prime = [2]
A = 55555
for L in range(3, A, 2):
    for L2 in prime:
        if L % L2 == 0:
            break
    else:
        prime.append(L)

cnt=0
ans=[]
for p in prime:
    if p%5==1:
        ans.append(p)
        cnt+=1
    if cnt==n:
        break
print(*ans)

Solution (Python):
import sys

input = sys.stdin.readline


def get_primes(n):
    sieve = [1] * n
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i:: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]


def main():
    N = int(input())
    primes = get_primes(55555)
    ans = []
    for p in primes:
        if len(ans) == N:
            break

        if p % 5 == 1:
            ans.append(p)

    print(*ans)


if __name__ == '__main__':
    main()

Solution (Python):
def is_prime(n):
  i = 2
  while i * i <= n:
    if n % i == 0:
      return False
    i += 1
  return True

N = int(input())

primes = []

for i in range(2,55556):
  if is_prime(i) == True:
    if i % 5 == 1:
      primes.append(i)
  if len(primes) == N:
    break

print(*primes)

Solution (Python):
def isprime(i):
  j=2
  while(j**2<=i):
    if(i%j==0):
      return False
    j+=1
  return True

n=int(input())
x=[]
for i in range(6,55552,5):
  if(isprime(i)):
    x.append(i)
  if(len(x)==n):
    break
print(*x)

Solution (Python):
primes = []

for n in range(6, 55556, 5):
    k = 2
    while k * k <= n:
        if not n % k:
            break
        k += 1
    else:
        primes.append(n)

print(*primes[:int(input())])

Solution (Python):
import sys
input = sys.stdin.readline
def isprime(n):
  if n <= 1:
    return False
  else:
    for i in range(2,int((n)**0.5+1)):
      if n%i == 0:
        return False
    return True

def solve():  
  n = int(input())
  query = []
  for i in range(2,55555):
    if isprime(i):
      if i%5 == 1:
        query.append(i)
  print(*query[0:n])
    
solve()

Solution (Python):
import math

from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def isprime(x):
    q = int(math.sqrt(x))  
    for i in range(2,q+1):   
        if x%i == 0:
            return False
    return True

def prime_division(x):
    q = int(math.sqrt(x))
    a = []
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            a.append([i,ex])
    if x>q:
        a.append([x,1])
    return a

def divisorlist(z): 
    if len(z)==1:
        return [z[0][0]**i for i in range(z[0][1]+1)]
    y = divisorlist(z[1:])
    s = []
    for i in range(z[0][1]+1):
        for j in y:
            s.append((z[0][0]**i)*j)
    return s

n = inn()
p = []
for i in range(11,55555,5):
    if isprime(i):
        p.append(i)
        if len(p)==n:
            break

pad = ''
for x in p:
    printn(pad + str(x))
    pad = ' '
print("")

Solution (Python):
N=int(input())
A=[]
for i in range(2,55556):
  if i%5==1:
    j=2
    while j<i:
      if i%j==0:
        break
      j+=1
    if i-j==0:
      A.append(i)
  if len(A)>=N:
    break
print(*A[:N])

Solution (Python):
P=[1 for i in range(55556)]
P[0]=0
P[1]=0
for i in range(2,55556):
    if P[i]==1:
        for j in range(2,55556):
            if i*j<=55555:
                P[i*j]=0
            else:
                break

ans=[]
for i in range(55556):
    if P[i]==1 and i%10==1:
        ans.append(i)
N=int(input())
print(*ans[:N])

Solution (Python):
def get_sieve_of_eratosthenes_new(n):
    import math
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

primelist=get_sieve_of_eratosthenes_new(55555)

N=int(input())
ans=[]
count=0
i=0
while count<N:
    if primelist[i]%5==1:
        ans.append(primelist[i])
        count+=1
    i+=1
print(*ans)