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

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

sieve = get_sieve_of_eratosthenes(55555)
ANS = []

for prime in sieve:
    if prime % 5 == 1:
        ANS.append(prime)

print(*ANS[:n])

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter




n=int(input())
def primes(n):
    m=int(pow(n,0.5))
    is_prime=[True]*(n+1)
    is_prime[0]=False
    is_prime[1]=False
    for i in range(2,m+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]]
s=set(primes(55555))
ans=[]
c=0
for i in s:
    if i%5==1:
        c+=1
        ans.append(i)
    if c==n:
      break
print(*ans)

Solution (Python):
import sys
import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


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


def main():

    N = in_n()
    p_list = primes(55555)
    M = len(p_list)

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def get_sieve_of_eratosthenes(n):
    """
    エラトステネスの篩
    """
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        return []
    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]
    return deque(data)

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

    """
    小さい素数から順に題意を満たすものを列挙するのはそもそも不可能らしい。
    結論は構成問題でした。５で割ってあまり１の素数を列挙すれば良いという、、、
    """

    ans = []
    cnt = 0
    for p in get_sieve_of_eratosthenes(55555):
        if cnt == N: break
        if p % 5 == 1:
            ans.append(p)
            cnt += 1
    print(" ".join(map(str, ans)))



if __name__ == "__main__":
    main()

Solution (Python):
import sys

import numpy as np


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


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def make_prime(U):
    is_prime = np.zeros(U, np.bool)
    is_prime[2] = 1
    is_prime[3::2] = 1
    M = int(U ** 0.5) + 1
    for p in range(3, M, 2):
        if is_prime[p]:
            is_prime[p * p :: p + p] = 0
    return is_prime, is_prime.nonzero()[0]


def main():
    N = int(input())
    _, primes = make_prime(55556)

    r_5 = []
    for p in primes:
        if p % 5 == 1:
            r_5.append(p)
    
    answer = r_5[:N]
    print(*answer)


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=1000):
    numbers = []
    
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    
    return numbers



A = callIsPrime(55556)
B = [0] * 56
j = 0
for i in range(1, len(A)):
  if A[i] % 5 == 1:
    B[j] = A[i]
    j += 1
  if j == 56:
    break
    

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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


def resolve():
    n = int(input())

    num = []
    for i in range(2, 55556):
        if i % 5 == 1 and is_prime(i):
            num.append(i)
    print(*num[:n])


if __name__ == '__main__':
    resolve()

Solution (Python):
import math
def prime_numbers(x):
    if x < 2:
        return []
    prime_numbers = [i for i in range(x)]
    prime_numbers[1] = 0
    for prime_number in prime_numbers:
        if prime_number > math.sqrt(x):
            break
        if prime_number == 0:
            continue
        for composite_number in range(2 * prime_number, x, prime_number):
            prime_numbers[composite_number] = 0
    return [prime_number for prime_number in prime_numbers if prime_number != 0]
n = int(input())
primes = prime_numbers(55555)
ans = []
cnt = 0
for i in primes:
    if i % 5 == 1:
        ans.append(i)
        cnt += 1
    if cnt == n:
        exit(print(*ans))

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

x=I()
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)


L=[]
for i in range(len(primes)):
    if primes[i]%5==1:
        L.append(primes[i])
for i in range(x):
    print(L[i],end=" ")

Solution (Python):
a = [0]*55556
N = int(input())
for i in range(2,55556):
    for j in range(2*i,55556,i):
        a[j] += 1
A = []
for i in range(2,55556):
    if a[i]==0 and i%5==1:
        A.append(str(i))
print(' '.join(A[:N]))

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache





MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n): return kaijo_memo[n]
  if(len(kaijo_memo) == 0): kaijo_memo.append(1)
  while(len(kaijo_memo) <= n): kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n): return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0): gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n): gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if n == r: return 1
  if n < r or r < 0: return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1: arr.append([temp, 1])
  if arr==[]: arr.append([n, 1])
  return arr


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


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b: a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n-1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n: return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

def base_10_to_n_without_0(X, n):
  X -= 1
  if X//n: return base_10_to_n_without_0(X//n, n)+[X%n]
  return [X%n]


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
P = []
for p in make_primes(55555):
  if p%5 == 1:
    P.append(p)
print(*P[:N])

Solution (Python):

def eratosthenes(n):
  l0=list(range(2,n+1))
  l1=[1]*(n+1)
  l1[0]=0
  l1[1]=0
  for li in l0:
    if li>int(n**0.5):
      break
    if l1[li]==1:
      k=2
      while k*li<=n:
        l1[k*li]=0
        k+=1
  ret=[i for i,li in enumerate(l1) if li==1]
  return ret
s=eratosthenes(55555)
ans=['2']
n=int(input())
for si in s:
  if str(si)[-1]=='3':
    ans.append(str(si))
print(' '.join(ans[:n]))

Solution (Python):


N = int(input())


MAX_N = 55556
primes = [True] * MAX_N
primes[0] = primes[1] = False
for p in range(2, MAX_N):
    if not primes[p]:
        continue
    for m in range(2 * p, MAX_N, p):
        primes[m] = False
lps = [i for i in range(2, MAX_N) if primes[i] and i % 5 == 1]

ans = lps[:N]
print(*ans)

Solution (Python):
n = int(input())
r = 55555
sosu = [1] * (r+1)
sosu[0],sosu[1] = 0,0
sosu[2] = 1
for i in range(2,int(r**0.5)+3):
    for j in range(i*2,r+1,i):
        sosu[j] = 0

a = []
for i in range(r+1):
    if sosu[i] == 1:
        if i%5 == 1:
            a.append(i)
            
ans = []
for i in range(n):
    ans.append(a[i])
    
print(*ans)

Solution (Python):

n = int(input())

def sleve_of_Eratosthenes(n):
    
    res = []
    if n == 1:
        return res
    ok = [False] * (1 + n)
    for i in range(2, n + 1):
        if ok[i]:
            continue
        tmp = 1
        res.append(i)
        while tmp * i <= n:
            ok[tmp * i] = True
            tmp += 1
    return res


prime = sleve_of_Eratosthenes(55555)
len_arr = 0
arr = []
for a in prime:
    if a % 5 == 1:
        arr.append(a)
        len_arr += 1
        if len_arr == n:
            break
print(*arr)

Solution (Python):

















import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    
    import itertools
    
    
    def primes(n):
        """ Input n>=6, Returns a list of primes, 2 <= p < n """
        zero = bytearray([False])
        size = n//3 + (n % 6 == 2)
        sieve = bytearray([True]) * size
        sieve[0] = False
        for i in range(int(n**0.5)//3+1):
            if sieve[i]:
                k = 3*i+1 | 1
                start = (k*k+4*k-2*k*(i & 1))//3
                sieve[(k*k)//3::2*k] = zero*((size - (k*k)//3 - 1) // (2 * k) + 1)
                sieve[start::2*k] = zero*((size - start - 1) // (2 * k) + 1)
        ans = [2, 3]
        poss = itertools.chain.from_iterable(
            itertools.zip_longest(*[range(i, n, 6) for i in (1, 5)]))
        ans.extend(itertools.compress(poss, sieve))
        return ans
    n=int(input())
    p=primes(55555)
    l=[]
    for i in p:
        if i%5==1:
            l.append(i)
    print(*l[:n])

    
resolve()

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

def primes(n):
    primes = [1] * (n+1)
    primes[0] = 0
    primes[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not primes[i] :
            continue
        for j in range(i * 2, n + 1, i):
            primes[j] = 0

    for i in range(len(primes)):
        if i %5 != 1:
            primes[i] = 0
    return primes


primes_list = primes(55556)





ans = []
for i in range(len(primes_list)):
    if primes_list[i]:
        ans.append(i)
        if len(ans) == n:
            break
ans = map(str, ans)
print(" ".join(ans))

Solution (Python):
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
n = int(input())
sosu = primes(55555)
ans = []
cou = 0
for i in sosu:
    if i % 5 == 2:
        ans.append(i)
        cou += 1
    if cou == n:
        print(*ans)
        exit()

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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] and i%5==1:
            ass.append(i)
    return ass

table = primes(55555)
print(*table[:N])

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



N = int(input())


prime_nums = []
append = prime_nums.append
for n in range(2, 55555):
    if is_prime(n) and n % 5 == 1:
        append(n)
        if len(prime_nums) == N:
            break

res = " ".join([str(num) for num in prime_nums])
print(res)
exit(0)

Solution (Python):
import math
def primes(n):
    max = math.sqrt(n)
    candidates = [i for i in range(2, n+1)]
    primes = []
    while candidates[0] <= max:
        primes.append(candidates[0])
        candidates = [candidates[i] for i in range(len(candidates)) if candidates[i] % candidates[0] != 0]
    primes.extend(candidates)
    return primes

def resolve():
    N = int(input())
    _primes = primes(55555)
    ans = []
    for p in _primes:
        if p%5==1:
            ans.append(p)
            if len(ans) == N:
                break
    print(" ".join(map(str, ans)))

    
if '__main__' == __name__:
    resolve()

Solution (Python):
Modoneprime = []
import math

for i in range (1, 11110):
	count = 0
	k = 5*i + 1
	for j in range (2, math.floor(math.sqrt(k))+1):
		if k%j ==0:
			count+=1
	if count > 0:
		continue
	else:
		Modoneprime.append(k)

N = int(input())

print(*Modoneprime[0:N])

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy


def primes():

    MAX = 60000
    prime = [False] * MAX
    prime[0] = prime[1] = True
    i = 2
    ret = []

    while i < MAX:
        if not prime[i]:
            if i % 5 == 1:
                ret.append(i)
            j = 2 * i
            while j < MAX:
                prime[j] = True
                j += i
        i += 1

    return ret

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

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def enum_primes(n):
    flag_num = (n + 1) // 2
    prime_flag = [True] * flag_num

    for num in range(3, int(n ** 0.5) + 1, 2):
        idx = (num - 1) // 2 - 1
        if prime_flag[idx]:
            for j in range(idx + num, flag_num, num):
                prime_flag[j] = False

    primes = [2]
    temp = [(i+1) * 2 + 1 for i in range(flag_num) if prime_flag[i]]
    primes.extend(temp)

    return primes


def main():
    n = int(readline())
    primes = set(enum_primes(55555))
    x = []
    l = 0
    for prime in primes:
        if len(x) == n:
            break
        if prime % 5 == 1:
            x.append(prime)
    print(*x)


if __name__ == '__main__':
    main()

Solution (Python):



from collections import defaultdict
import numpy

def sieve_of_eratosthenes(n):
  primes = [2]
  cands = numpy.array(list(range(3, n+1, 2)), dtype=numpy.int)
  while len(cands) != 0:
    prime = primes[-1]
    cands = cands[cands % prime != 0]
    if len(cands) == 0:
      break
    primes.append(cands[0])
  return primes

def main():
  n = int(input())
  k = 5
  primes = sieve_of_eratosthenes(55555) 
  counts = defaultdict(list)
  for prime in primes:
    counts[prime % k].append(prime)
    if len(counts[prime % k]) >= n:
      print(' '.join(list(map(str, counts[prime % k]))))
      return
    
    
if __name__=='__main__':
  main()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






N = getN()


prime = [2]
max = 55555
limit = int(math.sqrt(max))
data = [i + 1 for i in range(2, max, 2)]

while limit > data[0]:
    prime.append(data[0])
    data = [j for j in data if j % data[0] != 0]
prime = prime + data

prime = sorted(prime)

prime = [i for i in prime if i % 5 == 1]
print(*prime[:N])

Solution (Python):
def check_prime(k):
    '''
    素数の時1、合成数の時0を返す
    '''
    if k == 1:return 0
    num = int(k ** 0.5 // 1)
    for i in range(2, num + 1):
        if k % i == 0:return 0
    return 1

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

for i in range(2, 55556):
    if check_prime(i):
        prime.append(i)

rec = [2]
ind = 1
for i in range(n - 1):
    while True:
        if prime[ind] % 5 == 1:
            rec.append(prime[ind])
            ind += 1
            break
        ind += 1

print(*rec)

Solution (Python):
def main():
    n = int(input())
    prime_list = []
    i = 11
    while len(prime_list) < n:
        j = 2
        while j * j <= i:
            if i % j == 0:
                j = 0
                break
            j += 1
        if j:
            prime_list.append(i)
        i += 5
    print(" ".join(map(str, prime_list)))


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    n = int(input())

    res = []
    for i in range(2, 55556):
        if is_prime(i):
            if i % 5 == 1:
                res.append(i)
        if len(res) == n:
            print(*res)
            break


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    n = int(input())

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

    res = []
    for num in L:
        if num % 5 == 1:
            res.append(num)
        if len(res) == n:
            print(*res)
            break


if __name__ == '__main__':
    resolve()

Solution (Python):

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

U = 55555
is_prime = np.zeros(U, np.bool)
is_prime[2] = 1
is_prime[3::2] = 1
for p in range(3, U, 2):
    if p*p > U:
        break
    if is_prime[p]:
        is_prime[p*p::p+p] = 0

primes = np.where(is_prime)[0]
primes = primes[primes%5 == 2]
N = ir()
answer = primes[:N]
print(*answer)

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

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
L = []
for i in range(2,55555):
    if i%5==1:
        Ms = make_divisors(i)
        if len(Ms)==2:
            cnt+=1
            L.append(str(i))
    if cnt==55:
        break
print(" ".join(L[0:N]))

Solution (Python):
n = int(input())
MX = 55555
is_prime = [True]*MX
is_prime[0] = False
is_prime[1] = False
for i in range(2, MX):
    if not is_prime[i]:
        continue
    for j in range(2*i, MX, i):
        is_prime[j] = False
ans = [i for i, j in enumerate(is_prime) if j and i%5==1]
print(*ans[:n])

Solution (Python):
p={2,3};n,c,k=5,0,int(input())
while c<k:
  for j in p:
    if n%j==0:n+=1;break
  else:
    p.add(n)
    if n%5==1:print(n,end=" ");c+=1
print()

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

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

N = int(input())
ans = []
cnt = 0
for p in primes:
    if p % 5 == 1:
        ans += [p]
        cnt += 1
    if cnt == N:
        break

for p in ans:
    print(p, end=" ")

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

    p = 0
    for i in range(2,n+1):
        if is_prime[i]:
            p = i
            for j in range(p+p, n+1, p):
                is_prime[j] = False
        
        if p * p > n:
            break
    
    primes = []
    for i in range(2,n+1):
        if is_prime[i]:
            primes.append(i)

    return primes

def solve():
    N = int(input())
    primes = sieve(55555)
    ans = []
    for prime in primes:
        if prime % 5 == 1:
            ans.append(str(prime))

        if len(ans) == N:
            break
    
    print(" ".join(ans))

if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
prime_list = []
result = []
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) == True and i % 5 ==1:
    prime_list.append(i)
    
for p in range(n):
  result.append(prime_list[p])
  
print(*result)

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

primes = [2]
for x in range(3, 55556):
    chk = True
    for tmp in primes:
        if tmp ** 2 > x:
            break
        if x % tmp == 0:
            chk = False
    if chk:
        primes.append(x)

p2 = []
for prime in primes:
    if prime % 5 == 1:
        p2.append(prime)

p3 = p2[:n]

print(' '.join([str(pp) for pp in p3]))

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

def get_prime(n):
    if n <= 1:
        return []
    prime = [2]
    limit = int(math.sqrt(n))

    data = [i + 1 for i in range(2, n, 2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime + data

prime_list = get_prime(55555)
ans_list = []
for i in prime_list:
    if i % 5 == 1:
        ans_list.append(i)
    if len(ans_list) == N:
        break
for i in ans_list:
    print(i, end=' ')

Solution (Python):
import collections


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    N = int(input())
    tmplist = []
    
    for i in range(2, 55556):
        tmp = prime_factorize(i)
        if len(tmp) == 1:
            tmplist.append(i)
            
    
    
    
    ans = []
    for tmp in tmplist:
        if tmp%5 == 1:
            ans.append(tmp)
        if len(ans) == N:
            print(*ans)
            return

if __name__ == "__main__":
    main()

Solution (Python):


def sieve_of_eratosthenes(n):
    primes = []
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if is_prime[i]:
            primes.append(i)
            for j in range(i*2, n+1, i):
                is_prime[j] = False
    return primes

n = int(input())
A = sieve_of_eratosthenes(55555)

ans = []
for a in A:
    if a%5 == 1:
        ans.append(a)
        if len(ans) == n:
            break

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

Solution (Python):
import sys
input = sys.stdin.readline
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 set([i for i in range(n + 1) if is_prime[i]])
sosuu = primes(55555)
N=int(input())
ans=[]
ct=0
for i in sosuu:
 if i%5==1:
  ans.append(i)
  ct+=1
 if ct==N:
  break
print(*ans)

Solution (Python):
amari1 = []
amari2 = []
amari3 = []
amari4 = []

prime = [True] * 55556
prime[0] = False
prime[1] = False
for i in range(2, 55556):
  if not prime[i]:
    continue
  now = i
  while now + i <= 55555:
    now += i
    prime[now] = False
    
for i in range(2, 55556):
  if prime[i] == True:
    amari = i % 5
    if amari == 1:
      amari1.append(i)
    elif amari == 2:
      amari2.append(i)
    elif amari == 3:
      amari3.append(i)
    elif amari == 4:
      amari4.append(i)

N = int(input())
print(' '.join(map(str, amari1[:N])))

Solution (Python):
n = int(input())
prime5 = []
for i in range(1,5600):
  a = i * 10 + 1
  
  for j in range(3,int(a**0.5) + 1):
    if a % j == 0:
      break
      
  else: prime5.append(a)
print(*prime5[:n])

Solution (Python):
N = int(input())
ans = []
x = 6
while len(ans) < N:
    for y in range(2, int(x**0.5)+1):
        if x % y == 0:
            break
    else:
        ans.append(x)
    x += 5
print(*ans)

Solution (Python):
n = int(input())
prime5 = []
for i in range(1,5600):
  a = i * 10 + 1
  flag = True
  for j in range(3,int(a**0.5) + 1):
    if a % j == 0:
      flag = False
  if flag: prime5.append(a)
print(*prime5[:n])

Solution (Python):
n = int(input())
prime5 = []
for i in range(1,5600):
  a = i * 10 + 1
  flag = True
  for j in range(3,int(a**0.5) + 1):
    if a % j == 0:
      flag = False
  if flag: prime5.append(a)
print(*prime5[:n])

Solution (Python):
import numpy as np
def make_primes(U=55555):
    is_prime = np.zeros(U,np.bool)
    is_prime[2] = 1
    is_prime[3::2] = 1
    M = int(U**.5)+1
    for p in range(3,M,2):
        if is_prime[p]:
            is_prime[p*p::p+p] = 0
    return is_prime.nonzero()[0], is_prime
n = int(input())
a = []
primes, is_prime = make_primes()
for pi in primes:
    if pi % 5 == 1:
        a.append(pi)

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

Solution (Python):
n = int(input())
maxn = 55555
is_prime = [True if i%2 == 1 else False for i in range(0, maxn+1) ]
is_prime[0] = False
is_prime[1] = False
is_prime[2] = True 
for i in range(3, int(maxn**0.5) + 1, 2):
    if not is_prime[i]:
        continue
    for j in range(i*2, maxn+1, i):
        is_prime[j] = False

ps = [i for i in range(maxn+1) if is_prime[i]]

a = [] 
i = 2
while True:
    if ps[i] % 5 == 1:
        a.append(ps[i])
    if len(a) == n:
        break
    i += 1

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