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):
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
sosuu = [2]
A = 5555
for L in range(3, A, 2): 
    for L2 in sosuu:
        if L % L2 == 0:
            break 
    else: 
        sosuu.append(L)
ans=[]
count=0
for i in sosuu:
    if i%5==1:
        count+=1
        ans.append(i)
    if count==n:
        print(*ans)
        exit()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





pn=[2];A=1460
for L in range(3,A):
    chk=True
    for L2 in pn:
        if L%L2 == 0:chk=False
    if chk==True:
        pn.append(L)
arr=[]
for i in pn:
    if i%5==1:
        arr.append(str(i))

n=ii()

print(" ".join(arr[:n]))

Solution (Python):
def isPrime(x):
  """
  xが素数か否か判定する。

  Parameters
  ----------
  x: int
      自然数

  Returns
  -------
      True:素数
      False:素数ではない
  """
  if x<2:
    return False
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      return False
  return True


def sieve(x):
  """
  x以下の自然数が素数が否かを判定する。

  Parameters
  ----------
  x: int
      自然数

  Returns
  -------
  f:list
    True:素数
    False:素数以外
  """
  f=[True]*(x+1)
  f[0],f[1]=False,False

  for i in range(2,len(f)):
    if isPrime(i):
      for j in range(i*2,len(f),i):
        f[j]=False
  return f

n=int(input())
a=sieve(55555)
b=[]
for i,aa in enumerate(a):
  if aa==1:
    if i%5==1:
      b.append(i)
print(*b[:n])

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

N = int(input())

list = []

for i in range(55556):
    if(is_prime(i) and i % 5 == 1):
        list.append(i)
        
print(' '.join(str(item) for item in list[0:N]))

Solution (Python):
N=int(input())
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
ans=[]
for i in range(1,55555+1):
    if i%5==1:
        if is_prime(i):
            ans.append(i)
            if len(ans)==N:
                break
print(*ans)

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

n = int(input())
prime = []
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
for i in range(2, 55556):
    if is_prime(i) and i % 5 == 1:
        prime.append(i)
print(*prime[: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())

ans = []

for i in range(11111):
    if is_prime(5*(i+1)+1):
        ans.append(5*(i+1)+1)
        if len(ans) == n:
            for j in range(n):
                print(ans[j], end=' ')
            print()
            exit()

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

import math

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

    for i in range(2, int(math.sqrt(n))+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)

S = sieve(55555)
T = []
for i in range(len(S)):
    if S[i]%5 == 1:
        T.append(S[i])
print(*T[0:n])

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    n=int(readline())
    p=primes(55555)
    q=[x for x in p if x%5==1]
    print(*q[:n])

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

if __name__=="__main__":
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
def main():
    N = int(input())
    P = []
    for k in range(2,2000):
        f = 1
        for i in range(2,int(k**(1/2))+2):
            if k%i == 0:
                f = 0
                break
        if f == 1 and k%5 == 1:
            P.append(k)
    print(*P[:N])
if __name__ == '__main__':
    main()

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

def era(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(2*i, n+1, i):
            is_prime[j] = False
    
    return [i for i in range(n+1) if is_prime[i]]

N = int(input())
p = era(55555)
ans = []

for pi in p:
    if pi%5==1 and len(ans)<N:
        ans.append(pi)

print(*ans)

Solution (Python):
from math import sqrt

N = int(input())


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


ans = []
n = 2
while len(ans) < N:
    if is_prime(n):
        ans.append(n)
    n += 5

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

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

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

iter = 0
ans = []
for i in range(2, 55556):
    if is_prime(i) and i % 5 == 1:
        ans.append(i)
        iter += 1
        
    if iter == n:
        break

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

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

n = int(input())
ans = []
for i,p in enumerate(sieve(55555)):
    if p and i%5 == 1:
        ans.append(i)
        if len(ans) == n: break
print(*ans)

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

fact=[True]*55556
fact[0]=False
fact[1]=False
ans=[]
for i in range(2,len(fact)):
  if fact[i]:
    if i%5==1:
      ans+=[i]
      if len(ans)==n:
        print(*ans)
        break
    for j in range(i*2,len(fact),i):
      fact[j]=False

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

def is_prime(n):
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True
    
num = 11
tmp = 0
while 1:
    if is_prime(num):
        print(num, end = " ")
        tmp += 1
    num += 10
    if n == tmp:
        exit()

Solution (Python):
import sys
import math

N = int(sys.stdin.readline().rstrip())

def sieve_of_erastosthenes(num):
    input_list = [
        False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True
        for i in range(num)
    ]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):
        if serial >= sqrt:
            return [i for i, b in enumerate(input_list) if b == True]
        for s in range(serial**2, num, serial):
            input_list[s] = False

primes = sieve_of_erastosthenes(55555)

ans = []

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

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

Solution (Python):
class Sieve: 
    
    def __init__(self, n=1):
        self.f = [0 for _ in range(n+1)]
        self.f[0] = -1
        self.f[1] = -1
        self.primes = []
        for i in range(2, n+1):
            if self.f[i]:
                continue
            self.primes.append(i)
            self.f[i] = i
            for j in range(i*i, n+1, i):
                if not self.f[j]:
                    self.f[j] = i
    
    def isPrime(self, x):
        return self.f[x] == x
    
    def factorList(self, x):
        res = []
        while x != 1:
            res.append(self.f[x])
            x //= self.f[x]
        return res
    
    def factor(self, x):
        fl = self.factorList(x)
        if not len(fl):
            return []
        res = [[fl[0], 0]]
        for p in fl:
            if res[-1][0] == p:
                res[-1][1] += 1
            else:
                res.append([p, 1])
        return res

n = int(input())

s = Sieve(55555)
ans = []
i = 11
while len(ans) < n:
    if s.isPrime(i):
        ans.append(i)
    i += 10
print(*ans)

Solution (Python):

import sys
input = sys.stdin.readline




N = 55555
primes = []
is_prime = [True]*N
for i in range(2,N):
    if is_prime[i]:
        primes.append(i)
        j = 2
        while i*j < N:
            is_prime[i*j] = False
            j += 1




N = int(input())

Ans = []


for p in primes:
    if p%5 == 1:
        Ans.append(p)

print(*Ans[0:N])

Solution (Python):


import sys























from itertools import combinations, combinations_with_replacement






def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    import math
    class Eratos:
        def __init__(self, num):
            '''
            O(nlglgn) で num までの素数判定テーブルを作る
            >>> e = Eratos(10)
            >>> e.table
            [False, False, True, True, False, True, False, True, False, False, False]
            '''
            assert(num >= 1)
            self.table_max = num
            
            self.table = [False if i == 0 or i == 1 else True for i in range(num+1)]
            for i in range(2, int(math.sqrt(num)) + 1):
                if self.table[i]:
                    for j in range(i ** 2, num + 1, i):    
                        self.table[j] = False
        
        def is_prime(self, num):
            '''
            O(1) で素数判定を行う
            >>> e = Eratos(100)
            >>> [i for i in range(1, 101) if e.is_prime(i)]
            [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]
            '''
            assert(num >= 1)
            if num > self.table_max:
                raise ValueError('Eratos.is_prime(): exceed table_max({}). got {}'.format(self.table_max, num))
            return self.table[num]
        
        def prime_factorize(self, num):
            '''
            O(√n) で素因数分解を行う
            >>> e = Eratos(10000)
            >>> e.prime_factorize(6552)
            {2: 3, 3: 2, 7: 1, 13: 1}
            '''
            assert(num >= 1)
            if int(math.sqrt(num)) > self.table_max:
                raise ValueError('Eratos.prime_factorize(): exceed prime table size. got {}'.format(num))
            
            factorized_dict = dict()
            candidate_prime_numbers = [i for i in range(2, int(math.sqrt(num)) + 1) if self.is_prime(i)]
            
            
            for p in candidate_prime_numbers:
                if num == 1:    
                    break
                if num % p == 0:
                    cnt = 0
                    while num % p == 0:
                        num //= p
                        cnt += 1
                    factorized_dict[p] = cnt
            if num != 1:
                factorized_dict[num] = 1
            return factorized_dict
        
        def enum_divisor(self, num):
            '''
            O(√n) で約数列挙を行う
            >>> e = Eratos(10000)
            >>> e.enum_divisor(4)
            [1, 2, 4]
            >>> e.enum_divisor(19)
            [1, 19]
            >>> e.enum_divisor(100)
            [1, 2, 4, 5, 10, 20, 25, 50, 100]
            '''
            divisor_small = []
            divisor_large = []
            for i in range(1, int(math.sqrt(num)) + 1):
                if num % i == 0:
                    divisor_small.append(i)
                    if i != num // i:
                        divisor_large.append(num // i)
            divisor_large.reverse()
            return divisor_small + divisor_large
    

    def satisfy_composite(eratos, p, possible_four_sum):
        
        for elm in possible_four_sum:
            if eratos.is_prime(elm + p):
                return False
        return True


    n = ii()

    eratos = Eratos(55555 * 5)
    prime_list = [i for i in range(17, 55556) if eratos.is_prime(i)]
    ans = list(filter(lambda x: x%5==1, prime_list))[:n]

    print(*ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
ans = []
for p in range(7, 55555, 10):
    pr, j = True, 3
    while j * j <= p:
        if p % j == 0:
            pr = False
            break
        j += 2
    if pr:
        ans.append(p)
        if len(ans) == N:
            break
print(*ans)

Solution (Python):
import sys
import itertools

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()


N = ni()
M = 55555


def solve():
    ans = []
    for p in range(7, M, 10):
        pr, j = True, 3
        while j * j <= p:
            if p % j == 0:
                pr = False
                break
            j += 2
        if pr:
            ans.append(p)
            if len(ans) == N:
                break
    print(*ans)


solve()

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

result = []
sieve = [0] * (55555  + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, 55555 + 1):
    if sieve[i] != 0:
        continue
    if i % 5 == 1:
        result.append(i)
        if len(result) == N:
            break
    sieve[i] = i
    for j in range(i * i, 55555 + 1, i):
        if sieve[j] == 0:
            sieve[j] = i
print(*result)

Solution (Python):
def isprime(num):
	for k in range(2, int(num**0.5)+1):
		if num % k == 0:
			return False
	return True

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

for i in range(2, 55555):
	if i % 5 == 1:
		if isprime(i):
			pl.append(i)

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

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

def primes(n):
    if n < 4:
        return []
    else:
        pri = [2]
        k = 3
        while k*k <= n:
            for i in pri:
                if k%i == 0:
                    break
                elif i == pri[-1]:
                    pri.append(k)
            k += 2
        return pri

ps = primes(55555**2)
p1 = []
for i in ps:
    if i%10 == 1:
        p1.append(i)
    if len(p1) == n:
        break

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

Solution (Python):
from math import floor

n = int(input())

ans_list = []
ans_num = 0
ans = 1
while ans_num < n:
    ans += 5
    for i in range(2, floor(ans ** 0.5) + 1):
        if ans % i == 0:
            break
    else:
        ans_list.append(ans)
        ans_num += 1
print(*ans_list)

Solution (Python):
list_ = []

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(55555 / 5)

for i in range(1,n):
    cand = 1 + 5 * i
    if is_prime(cand):
        list_.append(cand)

k = int(input())

st = str()

for i in range(k):
    if i == 0:
        st  =  str(list_[i])
    else:
        st = st + ' ' + str(list_[i])

print(st)

Solution (Python):
list_ = []

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(55555 / 5)

for i in range(1,n):
    cand = 1 + 5 * i
    if is_prime(cand):
        list_.append(cand)

k = int(input())

st = str()

for i in range(k):
    if i == 0:
        st  =  str(list_[i])
    else:
        st = st + ' ' + str(list_[i])

print(st)

Solution (Python):
def sosuu(A, cnt):
    sosuu=[2]
    ans=[] 
    for L in range(3,A,2):
        for L2 in sosuu:
            if L%L2==0:
                break
        else:
            sosuu.append(L)
            if L%5==1:
                ans.append(L)
                cnt-=1
                if cnt==0:
                    break
    return ans
n=int(input())
print(*sosuu(55555,n))

Solution (Python):
def primes(n):
    if n == 2:
        return [2]
    nums = list(range(2, n + 1))
    primes = list()
    while len(nums) > 0:
        primes.append(nums[0])
        tmp = list()
        for n in nums[1:]:
            if n % nums[0] > 0:
                tmp.append(n)
        nums = tmp
    return primes


def main():
    N = int(input())
    ps = primes(10000)
    ans = list()
    for p in ps:
        if p % 5 != 1:
            continue
        ans.append(p)
        if len(ans) >= N:
            break
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()

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

import math
def isPrime(num):
    if num < 2: return False
    elif num == 2: return True
    elif num % 2 == 0: return False
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False
    return True
def callIsPrime(input_num):
    numbers = []
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)
    return numbers

tmp=callIsPrime(10000)
result=[]
cnt=0
for item in tmp:
    if item%5==1:
        result.append(item)
        cnt+=1
    if cnt==n:
        break

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

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

prime = []

for i in range(11,55556,2):
    flag = True
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            flag=False
            break
    if flag:
        prime.append(i)
        
prime_mod1 = []

for i in prime:
    if i%5==1:
       prime_mod1.append(i)
print(*prime_mod1[:n])

Solution (Python):
from math import factorial

k = int(input())
n = 10000
primes = [2]
for i in range(3, n, 2):
    all(i % p != 0 for p in primes) and primes.append(i)

primes = [i for i in primes if i%5 == 1][:k]
print(*primes)

Solution (Python):
import math


def isPrime(num):
    if num < 2:
        return False
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    return True


def callIsPrime(input_num=1000):
    numbers = []
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    return numbers


n = int(input())
pms = callIsPrime(55555)

ret = []

for item in pms:
    if item % 5 == 1:
        ret.append(item)

print(" ".join(map(str, ret[: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())
prime = primes(55555)
ans = [0]*N
for i in range(N):
    for k in prime:
        if k % 5 == 1 and k not in ans:
            ans[i] = k
            break
print(*ans)

Solution (Python):
def primes(n):
    i = 1
    p = [2]
    while i+2 <= n:
        flag = True
        i += 2
        for j in range(3, int(i**(1/2))+1, 2):
            if i % j == 0:
                flag = False
                break
        if flag:
            p.append(i)
    return p
n = int(input())
l = primes(55555)
l = [i for i in l if i % 5 == 1]
print(*l[:n])

Solution (Python):
N = int(input())
def prime(n):
    flag = False
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
            break
    return True
    

L = []
for i in range(2,55556):
    if prime(i) and i%5 == 1:
        L.append(i)
        if len(L) == N:
            break
print(*L[:N])

Solution (Python):
N = int(input())
def prime(n):
    flag = False
    for i in range(2,int(n**0.5)+1):
        if n%i == 0:
            return False
            break
    return True
    

L = []
for i in range(2,55556):
    if prime(i) and i%5 == 1:
        L.append(i)
print(*L[:N])

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

Nmax = 55555
f = [-1 for i in range(Nmax)]

for i in range(2,Nmax):
    if f[i]==-1:
        f[i]=True
        for j in range(i+i,Nmax,i):
            f[j] = False

f[0]=False
f[1]=False
lis = []
for i in range(1,6000):
    nu = i*10+1
    if nu<=Nmax and f[nu]==True:
        lis.append(nu)

    if len(lis)>=n:
        break

print(*lis)

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

def main():
    N = int(input())
    PRIMES = [i * 10 + 1 for i in range(2, 146) if isprime(i * 10 + 1)]
    print(' '.join(map(str, PRIMES[:N])))

main()

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())
ans=[]
prime_numbers=primes(55555)
while True:
    cnt=0
    for n in prime_numbers:
        if n%5==1:
            ans.append(n)
            cnt+=1
        if cnt==N:
            break
    break
print(*ans)

Solution (Python):
N = 55556
dp = [1] * (N+1)
dp[0] =  dp[1] =  0

for i in range(2,N+1):
    if dp[i]:
        for j in range(i*i, N+1, i):
            dp[j] = 0
five_prime = []
for i in range(N):
    if dp[i] == 1:
        if i%5==1:
            five_prime.append(str(i))
N = int(input())
print (' '.join(five_prime[:N]))

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]


N = int(input())
Primes = primes(55556)
Ans = []
num = 0

while len(Ans) < N:
    if Primes[num] % 5 == 1:
        Ans.append(Primes[num])
        print(Primes[num], end=' ')
    num += 1

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

import math


def isPrime(num):
    
    if num < 2: return False
    
    elif num == 2: return True
    
    elif num % 2 == 0: return False

    
    
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    
    return True


def callIsPrime(input_num=1000):
    numbers = []
    
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    
    return numbers


L=callIsPrime(55555)
count=0
ans=[]
for l in L:
    if l%5==1:
        ans.append(l)
    if len(ans)==N:
        break
print(*ans)

Solution (Python):
def isprime(n):
  for i in range(2, n + 1):
    if n % i == 0:
      return False
    if i * i > n:
      break
  return True
n = int(input())
s = []
for i in range(2, 55556):
  if isprime(i) and i % 5 == 1:
    s.append(i)
    if len(s) == n:
      break
print(*s)

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


upper = 55555
count = {i: [] for i in range(5)}

for i in range(2, upper + 1):
    if is_prime(i):
        count[i % 5].append(i)

N = int(input())

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

Solution (Python):

N = int(input())

MAXA = 55555
P = []
X = [True]*(MAXA+1)
X[0] = X[1] = False
for i in range(MAXA+1):
    if X[i]:
        P.append(i)
        X[i::i] = [False]*(MAXA//i)
X = []
for p in P:
    if p%5==1:
        X.append(p)
print(*X[:N])

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

MAXA = 55555
P = []
X = [True]*(MAXA+1)
X[0] = X[1] = False
for i in range(MAXA+1):
    if X[i]:
        P.append(i)
        X[i::i] = [False]*(MAXA//i)
X = []
for p in P:
    if p%5==1:
        X.append(p)
print(*X[:N])

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

primes = [1] * (55555+1)
primes[0] = 0
primes[1] = 0
for i in range(len(primes)):
    if primes[i] == 0: continue
    pi = i*2
    while pi <= 55555:
        primes[pi] = 0
        pi += i

ans = []
for i, p in enumerate(primes):
    if i % 5 == 1 and p:
        ans.append(i)

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

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

maxn=55555

prime=[1]*(maxn+1)
prime[0]=0
prime[1]=0
plst=[]
for i in range(2,maxn+1):
    if prime[i]==1:
        if i%5==1:
            plst.append(str(i))
        for j in range(2,maxn//i+1):
            prime[i*j]=0

print(' '.join(plst[:N]))

Solution (Python):
def get_primes(n: int) -> list:
    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]]

N=int(input())
L=get_primes(10000)
ans=[]
for i in range(len(L)):
    if L[i]%5==1:
        ans.append(L[i])
    if len(ans)==55:
        break

print(*ans[:N])

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

cnt=0
L=[]
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

for num in range(2,55555+1):
    l=make_divisors(num)
    if len(l)==2:
        pass
    else:
        continue 
    if num%5==1:
        L.append(num)
        cnt+=1
    if cnt==N:
        break

print(*L)

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

def make_eratosthenes(n):
    A=[0]*(n+1)
    A[0],A[1]=-1,-1 
    for i in range(2,n+1):
        if A[i]==0:
            j=i
            while j<n:
                A[j]=i
                j+=i
    return A
E=make_eratosthenes(2000)
P=[]

for i in range(2001):
    if E[i]==i and i%5==1:
        P.append(i)
Ans=[]
for i in range(n):
    Ans.append(P[i])
print(*Ans,sep=" ")

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N = int(input())
    n = 55555
    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

    primes = []
    for i in range(2, n):
        if is_prime[i]:
            primes.append(i)

    ans = [2]
    cnt = 1
    for p in primes[1:]:
        a = p // 2
        if a % 5 == 1:
            ans.append(p)
            cnt += 1

            if cnt == N:
                break

    print(*ans, sep=" ")


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
List = [2]
Newlist = []

for i in range(3,10**4):
  for j in List:
    if i%j == 0:
      break
  else:
    List.append(i)

for j in List:
  if j%5 == 1:
    Newlist.append(j)

for j in range(N):
  print(Newlist[j], end=" ")

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


def elastotenesSieve(n):
  l1=list(range(2,n+1))
  l2=[]
  
  while True:
    if len(l1)==0:
      return l2
  
    n=l1[0]
    l2.append(n)
    for y in l1:
      if y%n==0:
        l1.remove(y)


def main():
  n=I()
  l=elastotenesSieve(55555)

  ans=[]
  cnt=0
  for x in l:
    if x%5==1:
      ans.append(x)   
      cnt+=1

    if cnt==n:
      break

  return ' '.join([str(x) for x in ans])


print(main())

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

Solution (Python):
n = int(input())
result = [2]
i = 1
while len(result) < n:
    num = 5*i -1
    for j in range(2, int(pow(num, 0.5))+1):
        while num%j==0:
            num //= j
    if num == 5*i-1:
        result.append(num)
    i += 1
print(*result)