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

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


def primes(x):
    if x < 2:
        return []
    primes = [i for i in range(x)]
    primes[1] = 0
    for p in primes:
        if p > math.sqrt(x):
            break
        if p == 0:
            continue
        for non_prime in range(2*p, x, p):
            primes[non_prime] = 0
    return [p for p in primes if p != 0]


def main():
    p = primes(55555)
    ans = []
    for q in p:
        if (q % 5) == 1:
            ans.append(q)
    N = int(input())
    print(*ans[0:N])


if __name__ == '__main__':
    main()

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


prime = get_sieve_of_eratosthenes(55555)
prime = [str(i) for i in prime if i % 5 == 1]

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

Solution (Python):
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    ls = [True] * 100001
    ls[0] = False
    ls[1] = False
    p = collections.deque()
    for i in range(2, 100000):
        if ls[i]:
            p.append(i)
            for j in range(i, 100000, i):
                if ls[j]:
                    ls[j] = False
    ans = []
    while True:
        if len(ans) == n:
            break
        else:
            pv = p.popleft()
            if pv % 5 == 1:
                ans.append(pv)
    print(*ans)


if __name__ == '__main__':
    solve()

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [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 data
cnt = 0
for i in get_sieve_of_eratosthenes(55555):
    if i % 5 == 1:
        print(i,end=" ")
        cnt += 1
    if cnt == N:
        break

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
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

i=0
j=2
li=[]
while(i<n):
    if is_prime(j*5+1):
        li.append(j*5+1)
        i+=1
    j+=1
print(" ".join(map(str,li)))

Solution (Python):
N = int(input())
lst = [0] * 55556
prime = []
for i in range(2, 55556):
    if lst[i] == 0:
        if i % 10 == 1:
            prime.append(i)
        for j in range(i, 55556, i):
            lst[j] = 1
    if len(prime) == N:
        print (*prime)
        exit()

Solution (Python):
import math

isprime = [True for _ in range(55559)]
isprime[0]=False
isprime[1]=False
for i in range(2,55559):
    if isprime[i]:
        for j in range(2,55558//i+1):
            isprime[i*j] =False

n=int(input())
res = []
for i in range(55559):
    if isprime[i] and i % 5 == 1:
        res.append(i)
print(" ".join(map(str,res[:n])))

Solution (Python):
p=55555 
l=[1]*p 
i=2 
while i*i<=p:
    if l[i]:
        for j in range(i*i,p,i):
            l[j]=0 
    i+=1 
l[0]=l[1]=0 
prms=[i for i in range(p) if l[i]]
n=int(input())
mod1=[i for i in prms if i%5==1]
if len(mod1)>=n:
    print(*(mod1[:n]))
    exit()
mod2=[i for i in prms if i%5==2]
if len(mod2)>=n:
    print(*(mod2[:n]))
    exit()
mod3=[i for i in prms if i%5==3]
if len(mod3)>=n:
    print(*(mod2[:n]))
    exit()

Solution (Python):
n=int(input())
lst=[]
for i in range(2,55555):
    for j in range(2,int(i**(1/2))+1):
        if i%j==0:
            break
    else:
        lst.append(i)
li=[]
count=0
for u in lst:
    if u%5==2:
        li.append(u)
        count+=1
        if count==n:
            break
print(*li)

Solution (Python):
n=int(input())
a=[]
for i in range(11,55556):
    if i%5==1 and i%2==1:
        f=0
        for j in range(2,round(i**0.5)+1):
            if i%j==0:
                f=1
                break
        if f==0:
            a.append(i)
print(*a[:n])

Solution (Python):
import math

n = int(input())
res = []
cnt = 0
candidate = 3


class Prime:
    seed_primes = [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]

    def is_prime(self, n):
        """
        prime test (hybrid)

        see also: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_brute_force(n)
        else:
            return self.is_prime_miller_rabin(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_brute_force(self, n):
        """
        brute force prime test
        use with is_prime_common if you want to skip seed_primes

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

    def is_prime_miller_rabin(self, n):
        """
        miller rabin prime test
        use with is_prime_common if you want to skip seed_primes

        see also
            algorithm: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
            implementation: https://qiita.com/srtk86/items/609737d50c9ef5f5dc59
            improvement: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """

        d = n - 1
        while d & 1 == 0:
            d >>= 1

        
        witnesses = self.get_witnesses(n)
        

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y * y) % n
                d <<= 1

            if y != n - 1 and d & 1 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 3825123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            return self.gcd(b, a)
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        """
        pseudo prime generator
        :param x:
        :param n:
        :param seed:
        :return: pseudo prime
        """
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        """
        find one of factor of n
        this function is based to Pollard's rho algorithm

        see also
            algorithm: https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm
            implementation: https://qiita.com/gushwell/items/561afde2e00bf3380c98

        :param n:
        :param seed:
        :return: factor
        """
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed + 1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes


prime = Prime()
while cnt < n:
    if prime.is_prime(candidate):
        res.append(candidate)
        cnt += 1
    candidate += 10
print(" ".join([str(i) for i in res]))

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

N=int(input())

l=[]

for i in range(2,55556):
    if len(l)>=N:
        break
    if isPrime(i) and i%5==1:
        l.append(i)

print(*l)

Solution (Python):
import math
PrimeList = [2]

def calc_prime(N):
    for i in range(3,N+1,2):
        x = int(math.sqrt(i))+1
        j = 0
        prime = True
        while j < len(PrimeList) and PrimeList[j] <= x:
            if i % PrimeList[j] == 0:
                prime = False
                break
            j += 1
        if prime:
            PrimeList.append(i)

calc_prime(55555)
AnsList = []
for p in PrimeList:
    if p % 5 == 1:
        AnsList.append(p)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines






















def prime(n):
    if n >= 2:
        prime_nums = [2]
        for i in range(3, n + 1):
            for p in prime_nums:
                if i % p == 0:
                    break
            else:
                prime_nums.append(i)
    return prime_nums

def main():
    n=int(input())
    p=prime(5555)
    li=[]
    i=0
    while len(li)<56:
        if p[i]%5==1:
            li.append(p[i])
        i+=1

    print(*li[:n])






if __name__ == '__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines













from itertools import combinations








def prime(n):
    if n >= 2:
        prime_nums = [2]
        for i in range(3, n + 1):
            for p in prime_nums:
                if i % p == 0:
                    break
            else:
                prime_nums.append(i)
    return prime_nums

def main():
    n=int(input())
    p=prime(55555)
    li=[]
    i=0
    while len(li)<56:
        if p[i]%5==1:
            li.append(p[i])
        i+=1

    print(*li[:n])






if __name__ == '__main__':
    main()

Solution (Python):
import math
n = int(input())
number = []
five_number = []

tmp = int(math.sqrt(55555))
count = 0

for i in range(2, tmp):
    count = 0
    for k in range(2, i):
        if i % k == 0:
            count = 1

    if count == 0:
        number.append(i)
        if i % 5 == 1:
            five_number.append(i)

for i in range(tmp, 55555):
    count = 0
    if len(five_number) == 55:
        break
    for k in number:
        if i % k == 0:
            count = 1

    if count == 0 and i % 5 == 1:
        five_number.append(i)

print(*five_number[0:n:])

Solution (Python):
import numpy as np
N = int(input())

U = 10**5
is_prime = np.full(U+1, True)
is_prime[:2] = False
for p in range(2, U+1):
    if p*p > U:
        break
    if is_prime[p]:
        is_prime[p*p::p] = False

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

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

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

N = int(input())

ans = []
i = 2
while (len(ans) < N):
  a = i*5+1
  if is_prime(a):
    ans.append(a)
  i += 1
print(*ans)

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

n = int(input())
P = primes(55555)
A = []
i = 0

while len(A)<n:
    if P[i] % 5 == 1:
        A += [P[i]]
    i += 1

print(*A)

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

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


A=[]
cnt=0
c=6

while True:
	if isprime(c):
		A.append(c)
		cnt+=1
	if cnt>=N:break
	c+=5

print(*A)

Solution (Python):
n=int(input())
import math
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
data=get_sieve_of_eratosthenes(55555)
b=[]
for i in range(len(data)):
    if data[i]%5==1:
        b.append(data[i])
print(*b[: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]]


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


if __name__ == "__main__":
    main()

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


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


if __name__ == "__main__":
    main()

Solution (Python):
prime = list(range(3, 2000, 2))
for p in prime:
    prime = [pp for pp in prime if (pp % p != 0) | (pp == p)]
n = int(input())
ans = 0
ans_list = []
for p in prime:
    if p % 5 == 1:
        ans += 1
        ans_list.append(p)
    if ans == n:
        break
print(*ans_list)

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

x = []
p = []
for i in range(2, 2000):
    if all(i%p_i for p_i in p):
        p.append(i)
        if i%5 == 1:
            x.append(i)
            if len(x) == N:
                break

print(*x)

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


prime = [2, 3]
ret = []
for i in range(5, 55555 + 1, 2) :
    j = 0
    flg = False
    while prime[j] * prime[j] <= i :
        if i % prime[j] == 0 :
            flg = True
            break
        j += 1
    if flg :
        continue
    prime.append(i)
    if i % 10 == 1 :
        ret.append(i)
        if len(ret) == N :
            break
    
print(*ret)

Solution (Python):
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table
is_prime,table = sieve(55555)
N = int(input())
table1 = list(map(lambda x:x%5,table))
ans = []
append = ans.append
for i in range(len(table)):
  if table1[i]==1:
    append(table[i])
  if len(ans)==N:
    break
print(*ans)

Solution (Python):

N = int(input())
import math


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

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

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

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

ans = [0 for i in range(N)]

def prime(n):
    c = 2
    while 0 < c <= n**0.5:
        if n%c == 0:
            c = -1
        c += 1
    if c == 0:
        return "No"
    else:
        return "Yes"
    
cnt = 0
c = 2
while cnt < N:
    if c%5 == 2:
        if prime(c) == "Yes":
            ans[cnt] = str(c)
            cnt += 1
    c += 1
    
print(' '.join(ans))

Solution (Python):
N=int(input())
SIZ=55556
prime=[True for i in range(SIZ)]
prime[0]=False
prime[1]=False

for num in range(SIZ):
    if prime[num]:
        times=2
        while num*times<SIZ:
            prime[num*times]=False
            times+=1
for num in range(SIZ):
    if prime[num] and num%5==1 and N>0:
        N-=1
        print(num,end=" ")
print()

Solution (Python):
n = int(input())
ps = list(range(55556))
ps[1] = 0
primes = []
for i in range(2, 55556//2):
  if ps[i] != 0:
    primes.append(i)
    for j in range(55556)[::i]:
      ps[j] = 0
primes = [p for p in primes if p % 5 == 1]
print(' '.join( map(str, primes[:n]) ))

Solution (Python):
def main():
    primes = [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]
    n = int(input())
    print(*primes[:n])

main()

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



def is_prime_all(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 is_prime

N = I()
is_prime = is_prime_all(55555)
now = 2
a = []
while now<=55555:
    if is_prime[now]==True:
        a.append(now)
    now += 5

print(*a[:N])

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

Solution (Python):
def primes(n):
    memo = [True] * (n + 1)
    i = 2
    while i * i <= n:
        if memo[i]:
            j = i << 1
            while j <= n:
                memo[j] = False
                j += i
        i += 1
    return [i for i in range(n + 1) if memo[i] and i >= 2]

N = int(input())

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

print(*ans)

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


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return table


def main():
    N = int(input())
    table = sieve(55555)
    P = []
    for p in table:
        if p%5==1:
            P.append(p)
    print(' '.join(map(str, P[:N])))


if __name__ == '__main__':
    main()

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


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return table


def main():
    N = int(input())
    table = sieve(55555)
    P = []
    for p in table:
        if p%5==1:
            P.append(p)
    print(' '.join(map(str, P[:N])))


if __name__ == '__main__':
    main()

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

def main():
    N = int(input())
    def prime(N):
        p_list = [True for _ in range(N+1)]
        p_list[0] = False
        p_list[1] = False
        for i in range(2,int(N**0.5)+1):
            if not p_list[i]:
                continue
            for j in range(i*2,N+1,i):
                p_list[j] = False
        return [i for i in range(N+1) if p_list[i]]

    pl = prime(55555)
    ans = []
    for i in pl:
        if (i-1)%5 == 0:
            ans.append(i)
        if len(ans) == N:
            print(*ans)
            exit()

if __name__ == "__main__":
    main()

Solution (Python):
import math


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


N = int(input())
answer = []
for i in range(2, 55555):
    if is_prime(i) and i % 5 == 1:
        answer.append(i)
    if len(answer) == N:
        break

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

Solution (Python):
import math

def main():

    N = int(input())
    ps = []
    for i in range(2, 55555+1):
        if isPrime(i) and i % 5 == 1:
            ps.append(i)
        if len(ps) == N:
            return ps


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

if __name__ == '__main__':
    output = main()
    print(" ".join(map(str, output)))

Solution (Python):
n=int(input())
listA=[29,59,89,149,179]
i=7
while len(listA)<n:
  for j in range(7,(30*i-1)//2+1):
    if (30*i-1)%j==0:
      break
    elif j==(30*i-1)//2:
      listA.append(30*i-1)
  i+=1
print(' '.join(map(str,listA)))

Solution (Python):
N = int(input())
primes = [2]
res = []
for i in range(3, 55556):
  p = len(primes)
  f = 1
  for j in range(p):
    if i % primes[j] == 0:
      f = 0
  if f:
    primes.append(i)
    if i % 5 == 1:
      res.append(i)
  if len(res) == N:
    print(*res)
    break

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

    
    if n % 5 == 1:
        return True
    else:
        return False

def main():
    N = int(input())
    num_list = []
    for i in range(1, 55556):
        if is_prime(i):
            num_list.append(i)
            if len(num_list) == N:
                print(*num_list)
                exit()

main()

Solution (Python):
n = int(input())
prime = [1]*55556
prime_num = []
for i in range(2,55556):
    if prime[i] and i%5 == 1:
        prime_num.append(i)
    t = 1
    while (t*i <= 55555):
        prime[t*i] = 0
        t += 1
print(*prime_num[:n])

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

def create_prime_numbers2(upper_num):
    data = [2] + list(range(3,upper_num+1,2))
    idx = 0
    length = len(data)
    primes=[]
    while length>0:
        prime = data[0]

        primes.append(prime)
        data = [d for d in data if d % prime != 0]
        idx += 1
        length = len(data)
    
    return primes


prime_nums = create_prime_numbers2(55556)

print(" ".join(map(str,[num for num in prime_nums if num%5 == 1][:N])))

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



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


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


P = eratosthenes(55555)
ans = [p for p in P if p % 5 == 1]

print(*ans[:N])

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

k = 55555
eratos = [0 for i in range(k+1)]
prime = []
prime_bool = {}
for i in range(2, k+1):
    if eratos[i] == 1:
        prime_bool[i] = 0
        continue
    prime.append(i)
    prime_bool[i] = 1
    for j in range(2, k+1):
        if i * j > k:
            break
        eratos[i*j] = 1

ans = []
m = 11
while len(ans) < n:
    if prime_bool[m] == 1 and m % 5 == 1:
        ans.append(m)

    m += 2

print(" ".join([str(a) for a in ans]))

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()


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


    return prime



print(*[i for i in sieve(55555) if i % 5 == 1][:n])

Solution (Python):
n=int(input())
da=[True for i in range(55555)]
da[0]=False
for i in range(240):
    no=(i+2)*2
    while(55555>no):
        da[no-1]=False
        no+=(i+2)
li=[[] for i in range(4)]
for i in range(55555):
    if(da[i]):
        li[(i+1)%5-1].append(i+1)

for i in range(4):
    if(len(li[i])>=n):
        for j in range(n-1):
            print(li[i][j],end=' ')
        print(li[i][n-1])
        break

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

def p_prime(n): 
    prime = [2]
    for i in range(3,n+1):
        flag = 0
        for j in prime:
            if i%j == 0:
                flag = 1
                break
            if i**0.5 < j:
                break
        if flag == 0:
            prime.append(i)
    return prime
A = [2]
prime = p_prime(55555)
for i in prime:
    if i%5 == 1:
        A.append(i)
        
Ans = A[:N]
print(*Ans)

Solution (Python):




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

def solve():
  n = int(input())
  query = []
  for i in range(3,2222):
    if isprime(i):
      if i%5 == 1:
        query.append(i)
  for i in range(n):
    print(query[i],end =" ")
      
solve()

Solution (Python):
from collections import deque
import sys
sys.setrecursionlimit(10**7)

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

def solve():
  n = int(input())
  query = []
  for i in range(3,1311):
    if isprime(i):
      if i%5 == 2:
        query.append(i)
  
  for i in range(n):
    print(query[i],end =" ")
      
solve()

Solution (Python):
from collections import deque
import sys
sys.setrecursionlimit(10**7)

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

def solve():
  n = int(input())
  query = []
  for i in range(3,55556):
    if isprime(i):
      if i%5 == 2:
        query.append(i)
  for i in range(n):
    print(query[i],end =" ")
      
solve()

Solution (Python):
"""考え方
素数リストをあらかじめ作成し、その中から適当にN個値を選ぶ。
そして、その全ての5個の合計が合成数になることを確認？

"""
N = int(input())

prims = [1] * 55555
prims[0] = 0
prims[1] = 0


for i in range(250):
  if prims[i] == 1:
    for j in range(2*i,55555,i):
      prims[j] = 0
      


list_ans = []
for i in range(55555):
  if (prims[i] == 1) and (i%5 == 1):
    list_ans.append(str(i))
    if len(list_ans) >= N:
      break
    
print(" ".join(list_ans))

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

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

if __name__ == "__main__":
    main()