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())

lis = []
slis = []
now = 2

while len(lis) < N:

    flag = True
    
    for i in slis:

        if now % i == 0:
            flag = False
            break

    if flag:
        slis.append(now)

        if now % 5 == 1:
                lis.append(now)

    now += 1

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

Solution (Python):
n=int(input())
pn=[2];A=2000
for L in range(3,A):
    chk=True
    for L2 in pn:
        if L%L2 == 0:chk=False
    if chk==True:pn.append(L)

l=[]
for i in pn:
    if i%5==1:
        l.append(i)

print(*l[:n])

Solution (Python):
Ps = []
M = [False]*55556
for i in range(2, 55556):
  if not(M[i]):
    Ps.append(i)
    for j in range(i, 55556, i):
      M[j] = True

Ps2 = list(filter(lambda p: p%5 == 1, Ps))

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

Solution (Python):
import sys,math,itertools
N = int(input())

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

P = primes(55555)
P = list(filter(lambda x: x % 5 == 1, P))
P = [str(x) for x in P]

print(" ".join(P[0:N]))

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 isPrime():
    MAX = 10**5
    is_prime = [1] * (MAX+1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, MAX+1):
        if is_prime[i]:
            for j in range(i*2, MAX+1, i):
                is_prime[j] = 0
    return is_prime

N = int(input())

p = isPrime()
a = []
for i in range(55556):
    if p[i]:
        if i % 5 == 1:
            a.append(i)

print(*a[:N])

Solution (Python):
import sys
def II(): return int(sys.stdin.readline())

def get_is_prime_tuple(n):  
    isPrime = [True for _ in range(n+1)]
    isPrime[0] = False
    isPrime[1] = False
    for j in range(4, n+1, 2): isPrime[j] = False  

    for i in range(3, int(n**0.5)+1):
        if not isPrime[i]: continue
        for j in range(i*i, n+1, i+i):  
            isPrime[j] = False
    return tuple(isPrime)

def main(): 
    isPrime = get_is_prime_tuple(55555)
    N = II()
    ans = []
    for i in range(2,55556):
        if isPrime[i] and i%5 == 1:
            ans.append(i)
            N -= 1
        if N == 0:
            break
    print(' '.join(map(str, ans)))
    
main()

Solution (Python):
import sys
def II(): return int(sys.stdin.readline())

def get_is_prime_tuple(n):  
    isPrime = [True for _ in range(n+1)]
    isPrime[0] = False
    isPrime[1] = False
    for j in range(4, n+1, 2): isPrime[j] = False  

    for i in range(3, int(n**0.5)+1):
        if not isPrime[i]: continue
        for j in range(i*i, n+1, i+i):  
            isPrime[j] = False
    return tuple(isPrime)

def main(): 
    isPrime = get_is_prime_tuple(55555)
    N = II()
    for i in range(2,55556):
        if isPrime[i] and i%5 == 1:
            print(i, end=' ')
            N -= 1
        if N == 0:
            break
    print('')
    
main()

Solution (Python):
import sys
def II(): return int(sys.stdin.readline())

def main(): 
    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]
    N = II()
    print(' '.join([str(t) for t in ans[:N]]))

main()

Solution (Python):
def primes(n,default=2):
    if n<3:return []
    sievebd=n//2-1
    sieve=[True]*sievebd
    limit=(int((n-1)**.5)-1)//2
    for i in range(limit):
        if sieve[i]:
            for j in range(2*i**2+6*i+3,sievebd,2*i+3):
                sieve[j]=False
    return [2]*(default==2)+[2*i+3 for i in range(default//2-1,sievebd) if sieve[i]]
P=primes(55555)
l=[]
n=int(input())
i=0
while len(l)<n:
    if P[i]%5==1:l.append(P[i])
    i+=1
print(*l)

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

candidates = [i for i in range(2, 55556)]
primes = []

while len(candidates) > 0:
    if candidates[0] > math.sqrt(55555):
        primes.extend(candidates)
        break
    t = candidates.pop(0)
    tmp = []
    for c in candidates:
        if c % t != 0:
            tmp.append(c)
    candidates = tmp
    primes.append(t)

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

print(*ans)

Solution (Python):
def is_prime(target, p_list):
    for p in p_list:
        if target%p == 0:
            return False, p_list
    if target <= 55555:
        p_list.append(target)
    return True, p_list

            

if __name__ == '__main__':
    N = int(input())
    p_list = [2, 3, 5, 7]
    answer = []
    for new in range(max(p_list)+1, 55555):
        is_p, p_list = is_prime(new, p_list)
        if is_p and new%5 == 1:
            answer.append(new)
            if len(answer) == N:
                break
    print(' '.join(map(str, answer)))

Solution (Python):
new=[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(*[new[i] for i in range(int(input()))])

Solution (Python):
def prime(n):
    natural=[]
    n=n+1
    N=[True for i in range(n)]
    N[0],N[1]=0,0
    for i in range(4,n,2):N[i]=False
    for i in range(3,int(n**0.5)):
        if N[i]==True:
            for j in range(i*2,n,i):N[j]=False
    for i in range(n):
        if N[i]==True:
             natural.append(i)
    return natural


box=prime(55555)
count=0
new=[]
for i in box:
    if i%5==1:
        new.append(i)
        count +=1
    if count>=55:break
print(*[new[i] for i in range(int(input()))])

Solution (Python):
def sieve_of_eratosthenes(n):
    prime=[]
    limit=int(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]

m=55555
Primes=sieve_of_eratosthenes(m)
k=(len(Primes))
A=[]
for p in Primes:
    if p%5==1:
        A.append(p)
n=int(input())
print(*A[:n])

Solution (Python):
p = []
for i in range(1,11111+1):
    flag = True
    N = i*5+1
    for j in range(2,int(N**0.5)+1):
        if N%j == 0:
            flag = False
            break
    if flag:
        p.append(N) 
N = int(input())
for i in range(N):
    print(p[i],end = " ")

Solution (Python):

import sys, math, fractions, itertools


def eratosthenes_sieve(n: int):
    """
    エラトステネスの篩を用いてn以下の素数を求める
    """
    table = [0] * (n + 1)
    prime_list = []
    
    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1
    
    return prime_list

def solve(N: int):
    L = eratosthenes_sieve(55555)
    S = []
    for l in L:
        if l % 5 == 1:
            S.append(l)
    print(' '.join([str(l) for l in S[:N]]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)

if __name__ == '__main__':
    main()

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

def makePrimes():
    primeList = []
    isPrime = [True for _ in range(55556)]
    isPrime[0] = False
    isPrime[1] = False

    for i in range(2, 55556):
        if not isPrime[i]:
            continue
        if i % 5 == 1:
            primeList.append(i)

        for j in range(i, 55556, i):
            isPrime[j] = False

    return primeList

primeList = makePrimes()
print(*primeList[:N])

Solution (Python):


def prime(x):
    i = x
    while True:
        f = False
        j = 2
        while i > j:
            if i % j == 0:
                f = True
                break
            j += 1
        if f == False:
            break
        i += 1
    return i


n = int(input())
l = list()
a = 6
i = 0
while i < n:
    a = prime(a+1)
    if a % 5 != 1:
        continue 
    l.append(a)
    i += 1

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

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

def makePrimes():
    primeList = []
    isPrime = [True for _ in range(55556)]
    isPrime[0] = False
    isPrime[1] = False

    for i in range(2, 55556):
        if not isPrime[i]:
            continue
        if i % 5 == 1:
            primeList.append(i)

        for j in range(i, 55556, i):
            isPrime[j] = False

    return primeList

primeList = makePrimes()
print(*primeList[:N])

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

primes = []
for n in range(2, 55556):
    i = 2
    prime = True
    while i**2 <= n:
        if n % i == 0:
            prime = False
            break
        i += 1
    if prime and n % 5 == 1:
        primes.append(n)

for i in range(N):
    print(primes[i], end=' ')
print()

Solution (Python):
N = int(input())
 
from itertools import combinations
 
def get_sieve_of_eratosthenes(n):
    prime = [2]
    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]

primes = get_sieve_of_eratosthenes(55555)

lst = []
for p in primes:
    if p%5==1:
        lst.append(p)

for i in range(N):
    print(lst[i], end=' ')

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

prime = []

for i in range(10,1145148101919+1):
    a = True
    for g in range(2, i-1):
        if i%g == 0:
            a = False
            break
    if a:
        if i%5==1:
            prime.append(i)
    if len(prime)==55:
        break
    
print(*prime[:N])

Solution (Python):
import math
def isprime(n):
    if n==1:return(False)
    if n==2:return(True)
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:return(False)
    return(True)
n=int(input())
l=[]
tmp=11
while len(l)<n:
    if isprime(tmp):l.append(tmp)
    tmp+=10
print(*l)

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

ans_array = [2]

num = 7

while len(ans_array) != N:
    for i in range(2,int(math.sqrt(num))+1):
        if num % i == 0:
            break
    else:
        ans_array.append(num)
    num += 5

ans_str = " ".join(map(str,ans_array))
print(ans_str)

Solution (Python):
def primes():
    D = {}
    q = 2
    while True:
        if q not in D:
            yield q
            D[q * q] = [q]
        else:
            for p in D[q]:
                D.setdefault(p + q, []).append(p)
            del D[q]
        q += 1


N = int(input())
ans = list()
for p in primes():
    if len(ans) >= N:
        break
    if p % 5 == 1:
        ans.append(p)

print(' '.join([str(p) for p in ans]))

Solution (Python):

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

cnt = 0
i = 0
primes = []
while cnt < 55:
    n = i*5 + 2
    if len(make_divisors(n)) == 2:
        primes.append(n)
        cnt += 1
    i += 1

N = int(input())
print(*primes[: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

N = int(input())

a = [0]*N
a[0]=3
a_candi=int(0)

for i in range(N-1):
    a_candi = a[i]+10
    while (a_candi<55555):
        if is_prime(a_candi):
            a[i+1]=a_candi
            break
        else:
            a_candi += 10

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

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


def sieve_eratosthenes(n):
    nums = [True] * (n+1)
    nums[0] = False
    nums[1] = False
    for i in range(2, math.ceil(math.sqrt(n))+1):
        if not nums[i]: 
            continue
        else:
            for j in range(i*2, n+1, i):
                nums[j] = False 
    return [i for i in range(n+1) if nums[i]]

primes = sieve_eratosthenes(55555)

ans = [i for i in primes if i%5 == 1]



print(*ans[:N])

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

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right

import re




def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 


N = i_inpl()
def sieve_of_eratosthenes(N):
    prime_table = [True] * N
    prime_table[0] = prime_table[1] = False

    for i, is_prime in enumerate(prime_table):
        if is_prime:
            for n in range(i*i, N, i):
                prime_table[n] = False
    return prime_table

primes = [ i for i, f in enumerate(sieve_of_eratosthenes(55556)) if f]

l = [ str(pi) for pi in primes if pi % 5 == 1]
print(" ".join(l[0:N]))

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())
p = [x for x in primes(55555) if x % 5 == 1]
print(' '.join(map(str, p[:n])))

Solution (Python):

n=int(input());i=j=0;a=[]
def p(n):
  if n==1:return False
  for i in range(2,int(n**0.5)+1):
    if n%i==0:return False
  return True
while i<n:
  if p(5*j+1):i+=1;a.append(5*j+1)
  j+=1
print(*a)

Solution (Python):
import sys
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
def main():
    N = int(input())
    p = sieve_of_eratosthenes(55555)
    res = []
    for i in p:
        if i % 5 == 1:
            res.append(i)
    print(*res[:N],sep = " ")
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)


if __name__ == "__main__":
    main()

Solution (Python):

def get_sosuu():
    sosuu_list = [2, 3, 5, 7, 11, 13, 17]

    for i in range(18, 55556):
        for ele in sosuu_list:
            if ele > int(i ** 0.5) + 1:
                sosuu_list.append(i)
                break
            if i % ele == 0:
                break
        else:
            sosuu_list.append(i)
    return sosuu_list


def amari(sosuu_list, num):
    amari1 = []
    for ele in sosuu_list:
        if ele % 5 == 1:
            amari1.append(ele)
            if len(amari1) == num:
                break
    return amari1


def main():
    num = int(input())

    sosuu_list = get_sosuu()
    amari1 = amari(sosuu_list, num)
    print(' '.join(list(map(str, amari1))))






if __name__ == '__main__':
    main()

Solution (Python):
def is_prime(n):
    if n%2==0:return False
    for i in range(3,int(n**0.5)+1,2):
        if n%i==0:return False
    return True
print(*[i for i in range(6,55556,5) if is_prime(i)][:int(input())])

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from math import *

N = int(input())
def primes(n):
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1, 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-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2, 3] + [3*i+1|1 for i in range(1, n//3-correction) if sieve[i]]
ps = primes(55556)
ps = [x for x in ps if x % 5 == 1]
print(*ps[:N])

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

Solution (Python):
from math import *
M=55555
tab=[True]*(M+1)
for i in range(2,int(sqrt(M))):
    j=2
    while i*j<=M:
        tab[i*j]=False
        j+=1

N=int(input())
ans=[]
for i in range(2, M+1):
    if tab[i] and i%5==1:
        ans.append(str(i))
        if len(ans)>=N:
            break
print(" ".join(ans))

Solution (Python):



import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n = int(input())

def get_prime(n):
    prime = []
    limit = math.sqrt(n)
    data = [i+1 for i in range(1,n)]
    while 1:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

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

Solution (Python):
n = int(input())
mx = 55555
ans = []
primes = [2]
for i in range(3, mx + 1, 2):
    if all(i % p != 0 for p in primes):
        primes.append(i)
        if i % 5 == 1:
            ans.append(i)
        if len(ans) == n:
            break
print(*ans)

Solution (Python):
from itertools import combinations
from fractions import gcd
import math


n = int(input())
mx = 55555
ans = []
primes = [2]
for i in range(3, mx + 1, 2):
    if all(i % p != 0 for p in primes):
        primes.append(i)
        if i % 5 == 1:
            ans.append(i)
        if len(ans) == n:
            break
print(*ans)

Solution (Python):
n = int(input())
mx = 55555
ans = []
primes = [2]
for i in range(3, mx + 1, 2):
    if all(i % p != 0 for p in primes):
        primes.append(i)
        if i % 5 == 1:
            ans.append(i)
        if len(ans) == n:
            break
print(*ans)

Solution (Python):
from itertools import combinations
from fractions import gcd
import math


n = int(input())
mx = 55555
ans = []
primes = [2]
for i in range(3, mx, 2):
    if all(i % p != 0 for p in primes):
        primes.append(i)
        if i % 5 == 1:
            ans.append(i)
        if len(ans) == n:
            break
print(*ans)

Solution (Python):
import sys



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

def mmp(n):
	ret=[]
	val=11
	while len(ret) < n:
		if isp(val):
			ret.append(val)
		val += 10
	return ret
		
def main():
	
	n = int(input())
	l=mmp(n)
	
	print(' '.join([str(v) for v in l]))
	
	


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
	else:
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

N = int(input())
prime = [v for v in range(2, 55556) if v % 2 != 0]

for i in range(int(55555 ** 0.5) + 1):
    t = prime[i]
    prime = [v for v in prime if v == t or v % t != 0]
    
ans = []
for v in prime:
    if v % 5 == 1:
        ans.append(v)
        if len(ans) == N:
            print(" ".join(map(str, ans)))
            exit()

Solution (Python):
prime1 = []
numberlist = []
for i in range(2, 55556):
	numberlist.append(i)
while numberlist[0] < 236:
	now = numberlist.pop(0)
	prime1.append(now)
	newnumberlist = []
	for i in range(0, len(numberlist)):
		if numberlist[i] % now != 0:
			newnumberlist.append(numberlist[i])
	numberlist = newnumberlist
prime2 = prime1 + numberlist

N = int(input())
anslist = []
for i in range(0, len(prime2)):
	if prime2[i]%5 == 1:
		anslist.append(prime2[i])
	if len(anslist) == N:
		break
ans = str(anslist[0])
for i in range(1, N):
	ans = ans + ' ' + str(anslist[i])
print(ans)

Solution (Python):
import math
def primes(x):
    x+=1
    if x < 2:
        return []

    prime = [i for i in range(x)]
    prime[1] = 0

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

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

p = primes(55555)
one = []
for x in p:
    if str(x)[-1]=='1':
        one.append(x)

for i in range(int(input())):
    print(one[i],end=' ')

Solution (Python):
from collections import deque


def generate_primes():
    yield 2

    n = 3
    while True:
        if is_prime(n):
            yield n
        n += 2


def is_prime(n):
    if n < 2:
        return False

    if n == 2:
        return True

    if n % 2 == 0:
        return False

    i = 3
    while i * i <= n:
        if n % i == 0:
            return False
        i += 2

    return True


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

i = 2
while len(primes) < n:
    if i % 5 == 1 and is_prime(i):
        primes.append(i)
    i += 1
print(*primes)

Solution (Python):
N = int(input())
def primes(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(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass
prime_l = primes(55555)
prime_l = [p for p in prime_l if p%5==1]
print(" ".join(map(str,prime_l[:N])))

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())
ps= primes(55555)

ans = []
for p in ps:
    if p % 5 == 3:
        ans.append(p)
    if len(ans) == N:
        break
print(" ".join(list(map(str,ans))))

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

def get_prime(n):
    l=[]
    i=2
    while n>0:
        flg=True
        for j in range(2,int(i**0.5)+1):
            if i%j==0:
                flg=False
                break
        if flg:
            l.append(i)
            n-=1
        i+=1
    return l

p=get_prime(1000)
a=[]
for i in p:
    if i%5==1:
        a.append(i)
    if len(a)==n:
        break
print(*a)

Solution (Python):
def prime_t(t):
    i=2
    while i**2<=t:
        if t%i==0:
            return 0
        i+=1
    return 1

def prime_list(tt):
    p_list=[]
    for i in range(2,tt+1):
        if prime_t(i):
            p_list.append(i)
    return p_list
d=prime_list(55555)
ans=[i for i in d if i%10==1]
n=int(input())
print(*ans[:n])

Solution (Python):
def gen_prime():
	yield 2
	yield 3
	n=0
	while 1:
		yield n+5
		yield n+7
		n+=6


def resolve():
	l=list(range(55556))
	l[1]=0
	p=gen_prime()
	for i in p:
		if i**2>55556:
			break
		if i in l:
			t=i+i
			while t<55556:
				l[t]=0
				t+=i
	prime=[i for i in l if i%5==1]
	n=int(input())
	ans=prime[:n]
	x=''
	for i in ans:
		x+=str(i)+' '
	print(x[:-1])

resolve()

Solution (Python):
p=[1]*1363
n=input()
i=2
while n:
  if p[i]:
    if i%10==1or i<3:
      print i,
      n-=1
    for j in range(i,1363,i):p[j]=0
  i+=1

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


def is_prime(num):
    div = 2
    ret = 1
    while True:
        if num % div == 0:
            ret = 0
            break
        div += 1
        if div * div > num:
            break
    if num == 2:
        ret = 1
    return ret


ans = [0] * N
p = 2
for i in range(N):
    while True:
        if is_prime(p):
            ans[i] = p
            break
        else:
            p += 5
    p += 5

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

Solution (Python):
def shave(n):
    n_root = int(n**0.5)
    candidate = [i for i in range(3,n+1,2)]
    for i in range(3,n_root+2,2):
        candidate = [ j for j in candidate if j == i or j % i != 0]   
    candidate = [2] + candidate
    return candidate

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


print(*prime_list[:n])

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

sosuu=[2]
sosuu2=[2]
ans=[]

for i in range(3,55556):
    for j in sosuu2:
        if i%j==0:
            break
    else:
        sosuu.append(i)
        if i<=int(55556**0.5)+1:
            sosuu2.append(i)

cnt=0
for j in sosuu:
    if cnt<N-1 and j%5==1:
        print(j,end=" ")
        cnt+=1
    elif cnt==N-1 and j%5==1:
        print(j,end="")
        break

Solution (Python):
N=int(input())
sosuu=[]
ans=[]
for i in range(2,55556):
    flag=True
    for s in sosuu:
        if i**0.5<s:
            break
        if i%s==0:
            flag=False
            break
    if flag:
        sosuu.append(i)
        if i%5==1:
            ans.append(i)
print(" ".join(map(str,ans[:N])))

Solution (Python):
n=int(input())
prime=[2,3]
ans=[]
for i in range(4,55556):
  for j in range(2,int(i**0.5)+1):
    if i%j==0:
      break
  else:
    prime.append(i)
for i in prime:
  if i%5==1:
    ans.append(i)
print(*ans[:n])

Solution (Python):
primes = [2]
for n in range(3, 55555 + 1, 2):
    is_prime = True
    for p in primes:
        if p * p > n:
            break
        if n % p == 0:
            is_prime = False
            break
    if is_prime:
        primes.append(n)
primes1mod5 = list(filter(lambda x: x % 5 == 1, primes))
N = int(input())
print(" ".join(map(str, primes1mod5[:N])))

Solution (Python):
def main():
	N = int(input())
	ps = [2]
	ans = ["2"]
	i = 3
	while len(ans) < N:
		is_prime = True
		for p in ps:
			if i % p == 0:
				is_prime = False
				break

		if is_prime:
			ps.append(i)
			if i % 5 == 2:
				ans.append(str(i))
		i += 1
	print(" ".join(ans))


if __name__ == '__main__':
    main()

Solution (Python):
L = [1 for i in range(55556)]
L[0] = 0
L[1] = 0
plist = []
for i in range(55556):
	if L[i] == 1:
		plist.append(i)
		c = 2
		while True:
			if i * c <= 55555:
				L[i * c] = 0
				c += 1
			else:
				break

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

N = int(input())
ans = []
for i in range(N):
	ans.append(str(plist5[i]))

print(" ".join(ans))

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

prime = eratosthenes(55555)
r1 = []
for p in prime:
    if p%5==1:
        r1.append(p)
r1 = [str(p) for p in r1][:int(input())]
print(' '.join(r1))

Solution (Python):

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

def primes(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(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

N = int(input())
primes = primes(55555)
primes_five = []
for p in primes:
    if p % 5 == 1:
        primes_five.append(p)

print(*primes_five[:N])

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())
l = []
for p in primes(55555):
    if p % 5 == 1:
        l.append(p)
print(' '.join(map(str, l[:n])))

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

primes = sieve(55555)

N = int(input())
ans = []
for i in range(55555//10):
    if len(ans) == N:
        break
    if primes[3+10*i] == 1:
        ans.append(3+10*i)
    else:
        pass
print(' '.join(map(str,ans)))