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):
N=int(input())
Primes=[2]
flag=0
for i in range(2,27778):
  for p in Primes:
    if i%p==0:
      flag=1
      break
    elif p**2>i:
      break
  if flag==0:
    Primes.append(i)
  flag=0
n=0
ans=[]
for p in Primes:
  if p%5==1:
    ans.append(str(p))
    n+=1
  if n>=N:
    break
print(" ".join(ans))

Solution (Python):
N = int(input())
Primes = [True for i in range(55556)]
for i in range(2, 55556):
    if Primes[i] == True:
        num = i * 2
        while num <= 55555:
            Primes[num] = False
            num += i

count, Ans = 0, []
for i in range(2, 55556):
    if Primes[i] == True and i % 5 == 1:
        Ans.append(i)
        count += 1
    if count == N:
        break

print(" ".join(map(str, Ans)))

Solution (Python):
def make_num(N):
    ans = [2,]
    ans_3 = []
    now_num = 3
    while len(ans_3) < N:
        flag = True
        for i in ans:
            if now_num%i == 0:
                flag = False
                break
        if flag:
            if str(now_num)[-1] == '3':
                ans_3.append(now_num)
            ans.append(now_num)
        now_num += 2
    return ans_3


N = int(input())
ans = make_num(N)


print(' '.join(map(str,ans)))

Solution (Python):

from sys import stdin

d_in = lambda: int(stdin.readline())  


UPPER_LIMIT = 55555
N = d_in()


ans = [2, 7]
primes = [2, 3, 5, 7]
for i in range(11, UPPER_LIMIT, 2):
    flag = True
    for p in primes:
        if i % p == 0:
            flag = False
    if flag:
        primes.append(i)
    if flag and (i % 5 == 2):
        ans.append(i)
    if len(ans) == N:
        break

print(*ans)

Solution (Python):
import math

n = int(input())

sq = int(math.sqrt(55555))

prime = [i for i in range(55556)]
prime[1] = 0
for i in prime:
    if i > sq:
        break
    if i == 0:
        continue
    for j in range(i*2, 55556, i):
        prime[j] = 0

prime_3 = []
count = 0
for i, p in enumerate(prime):
    if count == n:
        break
    if p % 10 == 3:
        prime_3.append(p)
        count += 1

print(*prime_3)

Solution (Python):
import math

P = [2]
for k in range(3,1400):
    f = 1
    for l in range(2,int(math.sqrt(k))+1):
        if k % l == 0:
            f = 0
            break
    if f==1:
        P.append(k)

Q = []
for p in P:
    if p%5 == 1:
        Q.append(p)

print(" ".join(map(str,Q[:int(input())])))

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

def is_prime(n):
    if n == 2: return True
    if n < 2 or n%2 == 0: return False
    m = 3
    while m*m <= n:
        if n%m == 0: return False
        m += 2
    return True

ans = []
for n in range(11,55556,5):
    if is_prime(n):
        ans.append(n)
        if len(ans) == N:
            break
print(*ans)

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

x=55555
import math 
L=math.floor(math.sqrt(x))

Primelist=[i for i in range(x+1)]
Primelist[1]=0
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]

ANS=[]
for p in Primes:
    if p%10==1:
        ANS.append(p)

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

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def make_prime_list(lower:int, upper:int) -> list:
    
    
    isPrime = [True]*upper
    primeList = []
    
    
    if upper <= 2:
        return primeList
    
    
    isPrime[0] = False
    isPrime[1] = False
    
    
    n = 2
    while n**2 <= upper:
        if isPrime[n]:
            res=2*n
            while res<upper:
                isPrime[res] = False
                res += n
                
        n += 1
    
    
    for n in range(lower,upper):
        if isPrime[n]:
            primeList.append(n)
        
    return primeList

n = ni()
prime_list = make_prime_list(1,55555+1)

ans = []

for p in prime_list:
    if p%5 == 1:
        ans.append(p)
        
    if len(ans) == n:
        break
    
print(*ans)

Solution (Python):



import math

N = 55555
prime = [True]*(N+1)
prime[0] = False
prime[1] = False

R = int(math.sqrt(N))

for i in range(2, R+1):
    if prime[i]:
        cnt = 2
        while i * cnt <= N:
            prime[i * cnt] = False
            cnt += 1



n = int(input())
ans = []
i = 2
cnt = 0
while cnt < n:
    if prime[i] and (i - 1) % 10 == 0:
        ans.append(i)
        cnt += 1
    i += 1

print(" ".join(map(str,ans)))

Solution (Python):
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(' '.join(a[:int(input())]))

Solution (Python):
n = int(input())
p = []
a = []
q = 2
while len(a) < n:
  f = 0
  for x in p:
    if q%x == 0:
      f = 1
      break
  if f == 0:
    p += [q]
    if q%5 == 1:
      a += [str(q)]
  q += 1
print(" ".join(a))

Solution (Python):
primes = [i for i in range(55555)]
primes[1] = 0 

for p in primes:
    if p > int(55555**(1/2)): break
    if p == 0: continue
    for non_prime in range(2 * p, 55555, p): primes[non_prime] = 0

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

cand = set([10*i+1 for i in range(5554)])
prime5 = list(set(prime) & cand)

N = int(input())
ans = []
for i in range(N):
    ans.append(prime5[i])
print(*ans)

Solution (Python):
def eratosthenes(limit):
  E = [1] * (limit + 1)
  E[0], E[1] = 0, 0
  prime_list = []
  for i, e in enumerate(E):
    if e:
      prime_list.append(i)
      for j in range(i, limit + 1, i):
        E[j] = 0
  return prime_list
N = int(input())
prime_list = eratosthenes(55555)
prime5 = [[] for i in range(5)]
for p in prime_list:
  prime5[p % 5].append(p)
ans = prime5[0]
for p5 in prime5:
  ans = p5 if len(p5) > len(ans) else ans
print(' '.join([str(x) for x in ans[:N]]))

Solution (Python):
def run(N):
    p_list = primes(555555)
    
    ret = []
    for p in p_list:
        if p % 5 == 1:
            ret.append(p)
        if len(ret) == N:
            break
    return ' '.join([str(p) for p in ret])


def primes(n):
    '''
    エラトステネスの篩にて、素数のリストを作成
    '''
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        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]]


def main():
    N = int(input())
    print(run(N))


if __name__ == '__main__':
    main()

Solution (Python):

import math

import numpy as np

n = int(input())
flag = np.ones(55555 + 1)

for i in range(2, int(math.sqrt(55555)) + 1):
    if flag[i] == 0:
        continue
    for j in range(2, 55555 // i + 1):
        flag[i * j] = 0

t = [i for i in range(2, 55555 + 1) if flag[i] == 1 and i % 5 == 1]

print(' '.join(map(str, t[:n])))

Solution (Python):
import math

def makePrime(x):
    x = int(x)
    x += 1
    count = 0
    if x%5 != 1:
        x += 6-x%5
    for i in range(2,int(math.sqrt(x)+1)):
        if x%i == 0:
            count = 1
            break
    if count == 1:
        return str(makePrime(x+1))
    else:
        return str(x)

N = int(input())
a = []
a.append(str(11))
for i in range(N-1):
    b = a[i]
    a.append(makePrime(b))
print(' '.join(a))

Solution (Python):
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        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]]

n=int(input())
p=primes(100*n)
a=[]
i=0
j=0
while i<n:
    if p[j]%10==1:
        print(p[j], end=" ")
        i +=1
        j +=1
    else:
        j+=1

Solution (Python):
from math import floor, sqrt


def isPrime(x):
    for d in range(2, floor(sqrt(x)) + 1):
        if x % d == 0:
            return False
    return x != 1

N = int(input())


anss = []
for i in range(11111):
    x = 5 * i + 1
    if isPrime(x):
        anss.append(x)
        if len(anss) == N: break

print(' '.join(map(str, anss)))

Solution (Python):
k=int(input())
n = 55555
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)
p1=[i for i in primes if i%5==1]
print(*p1[:k])

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

primes = []
nums = list(range(2, 55556))
while True:
    p = nums[0]
    if p > int(55556**(1/2)):
        primes += nums
        break
    primes.append(p)
    nums = [num for num in nums if num%p > 0]


ans = [p for p in primes if str(p)[-1] == '1']
print(' '.join(list(map(str, ans[:n]))))

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



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


def eratosthenes(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0, n) if s[i] and i > 1]


P = [p for p in eratosthenes(55556) if p % 5 == 1]
print(*P[:N], sep=" ")

Solution (Python):
import numpy as np

N=int(input())

fact = [i for i in range(1600)]
fact[0]=fact[1]=0
for i in range(2,40):
    tmp=i
    tmp*=i
    while tmp<1600:
        fact[tmp]=0
        tmp+=i
fact = np.array(fact)
fact = fact[fact!=0]
fact = fact[fact%5==1]

ans=str(fact[0])
for i in range(1,N):
    ans+=' {}'.format(fact[i])
print(ans)

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

def prime(n): 
    import math
    num_list = [i + 1 for i in range(2,n,2)]
    list_prime = [2]
    limit = math.sqrt(n)
    if n == 2:
        return list_prime
    else:
        while True:
            p = num_list[0]
            if p >= limit:
                return list_prime + num_list
            list_prime.append(p)
            num_list = [num for num in num_list if num % p != 0]

prime_list = prime(55555)
ans_list = [p for p in prime_list if p % 5 == 4]
ans = ans_list[:n]
for i in range(n):
    ans[i] = str(ans[i])
print(" ".join(ans))

Solution (Python):

N = int(input())

prime = [2]
for n in range(3,55555+1):
    flag = True
    for p in prime:
        if n%p==0:
            flag = False
            break
        if n<p*p:
            break
    if flag:
        prime.append(n)

ret = []
for n in prime:
    if len(ret)==N:
        break
    if n%5==1:
        ret.append(str(n))
print(" ".join(ret))

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



def is_prime(x):
    if x < 2: return False 
    if x == 2 or x == 3 or x == 5: return True 
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False 

    
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

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

ans = []
for i in plist:
  if i % 5 == 1:
    ans.append(i)


print(" ".join(list(map(str,ans[0:N]))))

Solution (Python):
def is_prime(p):
    if p == 1:
        return False
    for i in range(2, p):
        if p % i == 0:
            return False
    return True

n = int(input())
ans = []
for i in range(55555):
    if is_prime(i) and i % 5 == 1:
        ans.append(str(i))
    if len(ans) == n:
        break
print(" ".join(ans))

Solution (Python):
list1=[1 for _ in range(55555)]
list1[0]=0
list1[1]=0
for i in range(55555):
    if list1[i]==0:
        pass
    else:
        for j in range(2,55555):
            if i*j>55554:
                break
            else:
                list1[i*j]=0
list2=[]
count=0
for k in range(55555):
    if count==55:
        break
    if list1[k]==0:
        pass
    else:
        if k%10==1:
            list2.append(k)
            count+=1

N=int(input())
ans=str(list2[0])
for l in range(N-1):
    ans=ans+" "+str(list2[l+1])
print(ans)

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

P=[] 
for i in range(11,55556,10):
    p=1
    for j in range(2,int(i**0.5)+1):
        if i%j==0 :
            p=0
    if p==1 :
        P.append(i)



s=""
for i in range(n-1):
    s+=str(P[i])+" "
s+=str(P[n-1])

print(s)

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]]

N = int(input())
prime = primes(55555)
prime_five = []
for i in prime:
    if i % 5 == 1:
        prime_five.append(i)

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

Solution (Python):
go = [2, 7, 17, 37, 47, 67, 97, 107, 127, 137, 157, 167, 197, 227, 257, 277, 307,317, 337, 347, 367, 397, 457, 467, 487, 547, 557, 577, 587, 607, 617, 647, 677, 727, 757, 787, 797, 827, 857, 877, 887, 907, 937, 947, 967, 977, 997, 1087, 1097, 1117, 1187, 1217, 1237, 1277, 1297]
n = int(input())
print(" ".join(map(str, go[:n])))

Solution (Python):
e = [0, 0] + [1] * 55555
for i in range(2, int(55555 ** 0.5) + 1):
    if e[i] == 1:
        for j in range(i * i, 55555 // i, i): e[j] = 0
p = []
for i in range(55555):
    if e[i] == 1: p.append(i)

n = int(input())
ans = []
for x in p:
    if x % 5 == 1: ans.append(x)
    if (len(ans) == n): break
print(' '.join(str(x) for x in ans))

Solution (Python):
N = int(input())
p = [True] * 55555

p[0] = False
p[1] = False
for i in range(2, int(55555**0.5)):
    for j in range(i*2, 55555, i):
        if j % i == 0:
            p[j] = False

p = [str(i) for i, f in enumerate(p) if f == True and i % 5 == 1][:N]
print(" ".join(p))

Solution (Python):
N = int(input())
p = [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]

p = list(map(str, p[:N]))
print(" ".join(p))

Solution (Python):
n = int(input())
m = 10**4
isp = [1] * m
isp[0] = isp[1] = 0
for i in range(2, int(m**0.5)+1):
    if isp[i]:
        for j in range(i * i, m, i):
            isp[j] = 0

P = [i for i,j in enumerate(isp) if j>0 and i%5 == 1]
print(*P[:n])

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

def hurui(n):
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data
pp = hurui(1500)

N = int(input())

tmp = 0
ans = []
for p in pp:
	if p%5 == 1:
		ans.append(p)
		tmp += 1
	if tmp == N:
		break

print(' '.join(map(str,ans)))

Solution (Python):
import math
n = int(input())
ans = []
cou = 1
co = 0
 
def sossu(x):
  for i in range(2,math.ceil(math.sqrt(x))+1):
    if x % i == 0:
      return False
  return True
 
for i in range(n):
  while 1:
    cou += 1
    if sossu(5 * cou + 1):
      ans.append(str(5 * cou +1))
      break

      
print(" ".join(ans))

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

N = 10005
pre = [True] * N
pre[0], pre[1] = False, False
for i in range(2, N):
    if pre[i]:
        k = i * 2
        while k < N:
            pre[k] = False
            k += i

R = [i for i in range(1, N)]
preN = list(filter(lambda x: pre[x], R))

rec = []
for i in range(len(preN)):
    if preN[i] % 5 == 1:
        rec.append(preN[i])
    if len(rec) == n:
        break

print(" ".join(map(str, rec)))

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

p = []
l = [True for _ in range(55555 + 1)]
l[0] = False
l[1] = False

for i in range(2, 55555 + 1):
    if l[i]:
        j = i + i
        while j < 55555 + 1:
            l[j] = False
            j += i

ans = []
cnt = 0
for i in range(2, 55555 + 1):
    if l[i]:
        if i % 10 == 1:
            cnt += 1
            ans.append(i)
            if cnt == n:
                break
print(*ans)

Solution (Python):
N = int(input())
data = [19,
 29,
 59,
 79,
 89,
 109,
 139,
 149,
 179,
 199,
 229,
 239,
 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,
 1399,
 1409,
 1429,
 1439]
res =''
for i in range(N):
    res += str(data[i])
    res += ' '
print(res[:-1])

Solution (Python):
def prime(K):
    for i in range(2,K):
        if K%i == 0:
            return 0
    return 1
N = int( input())
ANS = []
K = 0
for i in range(11, 55555):
    if i%5 == 1:
        if prime(i) == 1:
            ANS.append(i)
            K += 1
    if K == N:
        break
for i in range(N-1):
    print(ANS[i], end = ' ')
print(ANS[N-1])

Solution (Python):
import math
N = int(input())
a = []
def so(k):
    n = True
    if k % 2 == 0 and k != 2:
      return False
    for divisor in range(2, math.floor(math.sqrt(k))+1):
      if k % divisor == 0:
        n = False
    return n
for i in range(2,55555):
  han = so(i)
  if han == True and i%5 == 1:
    a.append(i)
a = a[:N]
print(" ".join(map(str,a)))

Solution (Python):
print(*[2,7,17,37,47,67,97,107,127,137,157,167,197,227,257,277,307,317,337,347,367,397,457,467,487,547,557,577,587,607,617,647,677,727,757,787,797,827,857,877,887,907,937,947,967,977,997,1087,1097,1117,1187,1217,1237,1277,1297][:int(input())])

Solution (Python):
def ptbl():
    n_max = 55555
    arr = [True for _ in range(n_max + 1)]
    for i in range(2, n_max + 1):
        if arr[i]:
            j = i + i
            while j < (n_max + 1):
                arr[j] = False
                j += i
    res = []
    for i in range(2, n_max + 1):
        if arr[i]:
            res.append(i)
    return res

n = int(input())
ans = []
cnt = 0
for x in ptbl():
    if x % 10 == 1:
        ans.append(x)
        cnt += 1
        if cnt == n:
            break
print(' '.join(map(str, ans)))

Solution (Python):
PN = [i for i in range(55556)]

PN[0] = 0
PN[1] = 0
for i in range(2, 55556):
    j = i * 2
    while True:
        if PN[i] == 0:
            break
        if j >= len(PN):
            break
        PN[j] = 0
        j += i


N = int(input())
cnt = 0
for i in range(len(PN)):
    if cnt == N:
        break
    if PN[i] % 5 == 1:
        cnt += 1
        if cnt < N:
            print(i, end = " ")
        else:
            print(i)
            break

Solution (Python):
def prime_list(n):
    '''
    n以下の素数のリストを返す
    '''
    A = list(range(2, n + 1, 1))
    prime = []
    p_max = A.pop(0)    
    while A[-1] >= p_max ** 2:
        for n in A:
            if n % p_max == 0:
                A.remove(n)
        prime.append(p_max)
        p_max = A.pop(0)
    prime.append(p_max)
    prime += A
    return prime

N = int(input())
ans = ['2']
for prime in prime_list(1362):
    if len(ans) < N:
        if prime % 5 == 1:
            ans.append(str(prime))

print(' '.join(ans))

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

Prime = [2, ]
ans = []
i = 3

while(len(ans) < N):
    Pflag = True
    for p in Prime:
        if(i % p == 0):
            Pflag = False
            break

    if(Pflag is True):
        Prime.append(i)
        if(i % 5 == 1):
            ans.append(i)

    i += 2

S = ""
for p in ans:
    S += " " + str(p)

print(S[1:])

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

def prime(x):
    res = []
    arr = [True for _ in range(x + 1)]
    
    for i in range(2, x + 1):
        if arr[i]:
            j = i + i
            while j < x + 1:
                arr[j] = False
                j += i
    
    for i in range(2, x + 1):
        if arr[i]:
            res.append(i)

    return res

ans = []
for i in prime(55555):
    if i % 10 == 1:
        ans.append(i)
        if len(ans) == n:
            print(' '.join(map(str, ans)))
            exit()

Solution (Python):
print(" ".join(list(map(str, [p for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381] if p % 5 == 1][0:int(input())]))))

Solution (Python):
print(" ".join(list(map(str, [p for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381]
 if p % 5 == 1][0:int(input())]))))

Solution (Python):
import math

"""
解説:
数列に含まれる数のうちすべてが 「5 で割って 1 余る」 数であれば, ここから 5 個の整数を選んだ
時にこれらの合計は必ず 5 で割り切れます.（= 合計が 5 以外の数は全て合成数！）
"""

N = int(input())

def main():
    min = 5
    max = 55555
    primes = range(min, max + 1)

    sqrt = math.ceil(math.sqrt(max))
    for i in range(2, sqrt + 1):
        primes = list(filter(lambda n: n == i or n % i != 0, primes))

    
    ans = list(filter(lambda n: n % 5 == 1, primes))
    print(' '.join(map(lambda n: str(n), ans[:N])))

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
pns = [2]
for i in range(3, 1500):
    for pn in pns:
        if i % pn == 0:
            break
    else:
        pns.append(i)

print(' '.join([str(pn) for pn in pns if pn % 10 == 1][:N]))

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

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

nums = []
k = 11
while len(nums) <= n:
  if prime(k) == True:
    nums.append(k)
  k += 10

ans = str(nums[0])
i = 1
while i < n:
  ans = ans +' '+str(nums[i])
  i += 1
print(ans)

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


prime = primes(55555)
N = int(input())
print(' '.join((map(str,list(filter(lambda n:n%5==1, prime))[:N]))))

Solution (Python):

n = int(input())

def check(num):
    for i in  range(2,int(num ** 0.5)+1):
        if num % i == 0:
            return False
    else:
        return True
            
cnt = 0
p = 0
List = []
while cnt != n:
    p += 1
    num = 5 * p + 1
    if check(num):
        cnt += 1
        List.append(num)
    

print(" ".join([str(num) for num in List]))

Solution (Python):
def mark(s, x):
    for i in xrange(x + x, len(s), x):
        s[i] = False

def sieve(n):
    s = [True] * n
    for x in xrange(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in xrange(0,n) if s[i] and i > 1]

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

print ' '.join(map(str,ans[:n]))

Solution (Python):
MAX = 55555
def get_prime_array(N):
    f = [True] * (N + 1)
    for i in range(2, N + 1):
        if f[i]:
            for j in range(i + i, N + 1, i):
                f[j] = False
    return f

def m():
    n = int(input())
    f = get_prime_array(MAX)
    a = []
    for i in range(6, len(f)):
        if f[i] and i % 5 == 1:
            a.append(i)
            if len(a) == n:
                break
    ans = ""
    for j in a:
        ans += str(j) + " "
    return ans

print(m())

Solution (Python):
N=int(input())
L=[str(i) for i in [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,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381,1451]]

print(" ".join(L[:N]))

Solution (Python):
MAX = 55555
p = [1]*(MAX+1)
p[0], p[1] = 0, 0
pp = []

for i in range(2, MAX, 2):
  p[i] = 0

for i in range(3, int(MAX**0.5)+1, 2):
  if p[i]:
    for j in range(i*2, MAX, i):
      p[j] = 0

for i in range(MAX+1):
  if p[i] and i%5==1:
    pp.append(i)

n = int(input())
print(" ".join(map(str, pp[:n])))

Solution (Python):
N=int(input())
list=[str(i) for i in [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(" ".join(list[:N]))

Solution (Python):
N=int(input())
L=[str(i) for i in [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(" ".join(L[:N]))

Solution (Python):
N=int(input())
L=[str(i) for i in [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]]
print(" ".join(L[:N]))

Solution (Python):
N=int(input())
ans=[2]
i=7
flag=0
while(len(ans)<N):
  for j in range(2,int(i**0.5)+1):
    if i%j==0:
      flag=1
      break;
  if flag!=1:
    ans.append(i)
  i+=5
  flag=0
  
for i in range(len(ans)):
  print(ans[i],end=" ")

Solution (Python):
n=int(input())
ans=[]
isPrime=[True for i in range(55555+1)]
for i in range(2, 55555+1):
    if isPrime[i]:
        if str(i)[-1]=='3':
            ans.append(i)
            if len(ans)==n:
                break
        for j in range(2*i, 55555+1, i):
            isPrime[j]=False

for i in ans:
    print(i)

Solution (Python):
s=[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]
for i in s[:int(input())]:
    print(i,end=" ")

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

p=[3,13,23,43,53,
    73,83,103,113,163,
    173,193,223,233,263,
    283,293,313,353,373,
    383,433,443,463,503,
    523,563,593,613,643,
    653,673,683,733,743,
    773,823,853,863,883,
    953,983,1013,1033,1063,
    1093,1123,1153,1163,1193,
    1213,1223,1283,1303,1373]
for i in range(n):
    print(p[i],end=" ")

Solution (Python):
N = int(input())
numList = []

def isPrime(num):
    retVal = True
    if num % 2 == 0:
        retVal = False
    else:
        for n in range(3, num//2, 2):
            if num % n == 0:
                retVal = False
                break
    return retVal

num = 6
for i in range(N):
    for prime in range(num+5, 55555, 5):
        if isPrime(prime):
            num = prime
            numList.append(prime)
            break

ans = " ".join(map(str, numList))
print(ans)

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

prime = []

N = int(input())
i = 1
while(len(prime) < N):
    p = 5 * i + 1
    if(is_prime(p)):
        prime.append(p)
    i += 1

s = ""
for i in prime:
    s += str(i) + " "
print(s[:len(s)-1])