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

hurui = [True]*(55556)
for i in range(2, int(55555**0.5)+1):
    for j in range(i*2, 55556, i):
        hurui[j] = False
sosu = []
for i in range(2, 55556):
    if i%5 != 1:
        continue
    if hurui[i]:
        sosu.append(i)

print(*sosu[: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())

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

Solution (Python):
import math
n=int(input())
p=[]
for x in range(2,5555):
    t=True
    for y in range(2,math.ceil(math.sqrt(x))+1):
        if x%y==0:t=False
    if t:p.append(x)
c=0
ans=[]
for i in range(len(p)):
    if p[i]%5==1:
        ans.append(p[i])
        c+=1
    if c==n:break
s=''
for x in ans:
    s+=str(x)+' '
print(s)

Solution (Python):
INF = 55555
P = [1 for _ in range(55556)]
P[0]=0
P[1]=0
for i in range(2,int(55556**0.5)+1):
    for j in range(i*i,55556,i):
        P[j] = 0
N = int(input())
A = []
for i in range(11,55556,10):
    if P[i]==1:
        A.append(i)
    if len(A)==N:
        break
print(*A)

Solution (Python):
l=[]
for i in range(6,1382,5):
  f=True
  for j in range(2,int(i**0.5)+1):
    if i%j==0:
      f=False
      break
  if f:
    l.append(i)

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

Solution (Python):
N=int(input())
MAX = 55555*5 + 10
def makePrimeChecker(n):
    """
    エラトステネスの篩.
    nまでの自然数が素数かどうかを表すリストを返す.
    O(nloglog(n))
    """
    isPrime = [True] * (n + 1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if isPrime[i]:
            for j in range(i*i, n+1, i): 
                isPrime[j] = False
    return isPrime

is_prime = makePrimeChecker(MAX)
nums = []
for num in range(2, 55555+1):
    if is_prime[num]:
        if num % 5 == 1:
            nums.append(num)
ans = nums[:N]
print(*ans)

Solution (Python):
sosuu = [2]
A = 55555
for L in range(3, A, 2): 
    for L2 in sosuu:
        if L % L2 == 0:
            break 
    else: 
        sosuu.append(L)

a=sosuu

n=int(input())

ans=[]

l=0

for i in a:
  if i%5==1:
    ans.append(str(i))
    l+=1
    
  if l==n:
    break


print(' '.join(ans))

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys

def is_primes(n):
    n+=1
    primes = [1]*n
    primes[0] =0
    primes[1] =0
    for i in range(2,int(n**0.5)+1):
        if primes[i] ==1:
            for j in range(2*i,n,i):
                primes[j] = 0
    return primes
def iscomb(n):
    for p in primes:
        if p>n**0.5+1:
            return False
        if n%p==0:
            return True


n = ni()
nm=55555
isprimes = is_primes(nm)
primes = [p for p in range(nm) if isprimes[p]]
i=0
ans=[]
while len(ans)<n:
    if primes[i]%5==1:
        ans.append(primes[i])
    i+=1
print(*ans)

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


def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i] and i % 5 == 1:
            ass.append(i)
    return ass

prime_list = primes(55555)


ans = []
for i in range(n):
    ans.append(prime_list[i])
print(*ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect






sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  


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

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 = ni()
li = primes(10**7)
ct = 0
ans = []
for num in li:
    if num % 10 == 7:
        ct += 1
        ans.append(num)
        if ct == N:
            break 
print(*ans)

Solution (Python):
def main():
    n = int(input())
    p = [True] * 55556
    p[0] = False
    p[1] = False
    curr = 2
    while curr * curr <= 55555:
        if p[curr]:
            for i in range(curr * curr, 55556, curr):
                p[i] = False
        curr += 1
    fives = []
    for i in range(2, 55556):
        if p[i] and i % 5 == 1:
            fives.append(i)
    print(*fives[:n])
    

if __name__ == '__main__':
    main()

Solution (Python):

def main():
    n = int(input())
    p = [True] * 55556
    p[0] = False
    p[1] = False
    curr = 2
    while curr * curr <= 55555:
        if p[curr]:
            for i in range(curr * curr, 55556, curr):
                p[i] = False
        curr += 1
    fives = []
    for i in range(2, 55556):
        if p[i] and i % 5 == 1:
            fives.append(i)
    print(*fives[:n])
    

if __name__ == '__main__':
    main()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [1] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1)

    a = [2 * i + 1 for i in range(m) if p[i]]
    a[0] = 2
    return a


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

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

    print(*ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [1] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1)

    a = [2 * i + 1 for i in range(m) if p[i]]
    a[0] = 2
    return a


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

    primes = [p for p in prime_numbers(55555) if p % 2 and (p - 1) // 2 % 5 == 0]
    ans = primes[:N]

    print(*ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
def primesbelow(N):
    
    
    correction = N % 6 > 1
    N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6]
    sieve = [True] * (N // 3)
    sieve[0] = False
    for i in range(int(N ** .5) // 3 + 1):
        if sieve[i]:
            k = (3 * i + 1) | 1
            sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1)
            sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1)
    return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]]

k=primesbelow(10000000)
ones=[]
twos=[]
threes=[]
fours=[]
for i in k:
    if i%5==1:
        ones.append(i)
    if i%5==2:
        twos.append(i)
    if i%5==3:
        threes.append(i)
    if i%5==4:
        fours.append(i)

n=int(input())
print(*ones[5:5+n])

Solution (Python):
def primesbelow(N):
    
    
    correction = N % 6 > 1
    N = {0:N, 1:N-1, 2:N+4, 3:N+3, 4:N+2, 5:N+1}[N%6]
    sieve = [True] * (N // 3)
    sieve[0] = False
    for i in range(int(N ** .5) // 3 + 1):
        if sieve[i]:
            k = (3 * i + 1) | 1
            sieve[k*k // 3::2*k] = [False] * ((N//6 - (k*k)//6 - 1)//k + 1)
            sieve[(k*k + 4*k - 2*k*(i%2)) // 3::2*k] = [False] * ((N // 6 - (k*k + 4*k - 2*k*(i%2))//6 - 1) // k + 1)
    return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N//3 - correction) if sieve[i]]

k=primesbelow(10000000)
ones=[]
twos=[]
threes=[]
fours=[]
for i in k:
    if i%5==1:
        ones.append(i)
    if i%5==2:
        twos.append(i)
    if i%5==3:
        threes.append(i)
    if i%5==4:
        fours.append(i)

n=int(input())
print(*fours[5:5+n])

Solution (Python):
n = int(input())
s = [2]
ans = []
t = 1
for i in range(3,55556):
    flg = True
    for _ in s:
        if i % _ == 0:
            flg = False
    if flg:
        s.append(i)
        if i % 5 == 1:
            ans.append(str(i))
            t += 1
    if t > n:
        break
print(' '.join(ans))

Solution (Python):
N=int(input())
def eratosthenes(n):
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
l=eratosthenes(55555)
cnt=0
for i in l:
   if i%5==1:
      print(i,end=" ")
      cnt+=1
   if cnt==N:
      exit()

Solution (Python):
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]:
            a = list(str(i))
            if a[-1] == '1':
                ass.append(i)
    return ass


def main():
    N = int(input())
    ass = primes(55555)
    ans = []
    for i in range(N):
        ans.append(ass[i])
    print(*ans)
    

if __name__ == "__main__":
    main()

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

def Sieve_of_Eratosthenes(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] and i%5 == 1]

ans = Sieve_of_Eratosthenes(55555)

print(*ans[:N])

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

def Sieve_of_Eratosthenes(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
  

is_prime = Sieve_of_Eratosthenes(55555)
ans = []
i = 0

while N:
  if is_prime[1+5*i]:
    ans.append(1+5*i)
    N -= 1
  i += 1

print(*ans)

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

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

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

def main():
    N = NI()
    
    ls = []
    
    for n in range(1,55556):
        if is_prime(n):
            if n%5 == 1:
                ls.append(n)
                if len(ls) == N:
                    print(" ".join(list(map(str,ls))))
                    break
        

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
ans = []
x = 6

while len(ans)<N:
  for y in range(2,x):
    if x%y==0:
      break
  else:
    ans.append(x)
  x+=5

print(*ans)

Solution (Python):
import random
def isPrime(q,k=50):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True
ls = []
for i in range(6,55555+1,5):
    if isPrime(i):
        ls.append(i)
N = int(input())
print(*ls[:N])

Solution (Python):
def main():
    n = int(input())
    M = 55555
    Int = [i for i in range(M+1)]
    for i in range(2,len(Int)):
        if Int[i]!=0:
            for k in range(2,M//Int[i]):
                Int[i*k] = 0
    prm = []
    for i in Int:
        if i!=0 and i%5==1:
            prm.append(i)
    prm = prm[1:]
    print(' '.join([str(x) for x in prm[0:n]]))

if __name__ == "__main__":
    main()

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']
print(' '.join(l[:int(input())]))

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']
print(' '.join(l[:int(input())]))

Solution (Python):


import sys 
from math import sqrt
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())

M = 55555
p = [1]*(M+1)
p[0] = p[1] = 0

for x in range(2, int(sqrt(M))+1):
    if p[x]:
        for y in range(x*x, M+1, x):
            p[y] = 0


P = []
cnt = 0
for i in range(1,M+1):
    if p[i] and (i-1) % 5 == 0:
        P.append(i)

print(*P[:N])

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


N = int(input())
ans = []
t = 11
while len(ans) < N:
    if is_prime(t):
        ans.append(t)
    t += 5
print(*ans)

Solution (Python):
class Eratosthenes():  
    def __init__(self, N):  
        self.fact = [i for i in range(N + 1)]
        for i in range(2, int(N ** 0.5) + 1):
            if self.fact[i] < i:
                continue
            for j in range(i ** 2, N + 1, i):
                self.fact[j] = i
        self.prime = [i for i in range(2, N + 1) if i == self.fact[i]]

n = int(input())

prime = Eratosthenes(55555).prime
ans = [p for p in prime if p % 5 == 1]
print(*ans[:n])

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

X=[]

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

for i in range(2,55556):
    if j(i) and i%5==1:
        X.append(i)

print(*X[:n])

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

fact = [True] * 55556

fact[0],fact[1] = False, False

ans = []
cnt = 0
for i in range(2, len(fact)):
  if fact[i]:
    if i % 5 == 1:
      ans.append(i)
      cnt += 1
      if cnt == N:
        break
    for j in range(i * 2, len(fact), i):
      fact[j] = False

print(*ans)

Solution (Python):
dp = [0]*55556
dp[0] = 1
dp[1] = 1
prime = []
for i in range(55556):
    if dp[i] == 0:
        prime.append(i)
        for j in range(i, 55556, i):
            dp[j] = 1
Enable = []
for i in prime:
    if i % 5 == 1:
        Enable.append(i)
N = int(input())
for i in Enable[:N]:
    print(i, end=" ")

Solution (Python):

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


N = int(input())
cands = [i for i, p in enumerate(seive(1381)) if p and i % 5 == 1]
print(*cands[:N])

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


N = int(input())
cands = [i for i, p in enumerate(seive(1381)) if p and str(i)[-1] == "1"]
print(*cands[:N])

Solution (Python):
from itertools import combinations


def get_primes(N):
    primes = []
    for num in range(2, N + 1):
        for prime in primes:
            if num % prime == 0:
                break
        else:
            primes.append(num)
    return primes


N = int(input())

primes = get_primes(55555)


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

primes_5 = primes_5[:N]
print(*primes_5)

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

xxx=get_prime(55555)

zzz=[i for i in xxx if i%5==1]

n=int(input())

yyy=zzz[:n]

kkk=[str(i) for i in yyy]

print(' '.join(kkk))

Solution (Python):
import sys, math
from functools import lru_cache
from collections import deque

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

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

def main():
    N = ii()
    ans = []
    
    k = 2
    while len(ans) < N:
        if isPrime(k) and k%5==1:
            ans.append(k)
        k += 1

    print(*ans)

if __name__ == '__main__':
    main()

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

def eratosthenes(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]]

l=eratosthenes(55555)
ans=[]
for li in l:
    if li%5==1:
        ans.append(li)
print(*ans[: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())
ans_ls = [0] * n
i = 0
for prime in primes(55555):
    if prime % 5 == 1:
        ans_ls[i] = prime
        i += 1
        if i == n:
            break
print(*ans_ls)

Solution (Python):
from collections import Counter
def sieve_eratosthenes(n):
    primes = [0, 1] * (n // 2 + 1)                  
    if n % 2 == 0:                                  
        primes.pop()
    primes[1] = 0                                   
    primes[2] = 1                                   
    for p in range(3, int(n**0.5) + 2, 2):
        if primes[p]:
            for q in range(p * p, n + 1, 2 * p):    
                primes[q] = 0
    return primes

N = int(input())
M = 10**4
prime = sieve_eratosthenes(M)
P = []
for i in range(M):
    if prime[i]:
        if i%5==1:
            P.append(i)
print(*P[:N])

Solution (Python):



def generate_primes():
    from collections import defaultdict
    from itertools import count
    D = defaultdict(list)

    q = 2
    for q in count(2):
        if q in D:
            for p in D[q]:
                D[p+q].append(p)
            del D[q]
        else:
            yield q
            D[q*q].append(q)

N = int(input())
res = []
cnt = 0
for p in generate_primes():
    if p % 5 == 1:
        cnt += 1
        res.append(p)
    if cnt >= N:
        break

print(*res)

Solution (Python):
from itertools import combinations
n = int(input())
primes = []
for num in range(2, 55556):
    for prime in primes:
        if num % prime == 0:
            break
    else:
        primes.append(num)

primes_mod1 = []
for prime in primes:
    if prime % 5 == 1:
        primes_mod1.append(prime)
print(*primes_mod1[:n], sep=" ")

Solution (Python):
import itertools

n = int(input())
primes = [x for x in range(3, 55556, 2)]

for i in range(3, 237, 2):
    for j, p in enumerate(primes):
        if p <= i:
            continue
        if p % i == 0:
            primes[j] = 0
primes = [2] + [p for p in primes if p > 0]
aa = [p for p in primes if p <= 55555 and p % 5 == 1]
print(' '.join(map(str, aa[:n])))

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if is_prime[i]:
            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 resolve():
    N = I()

    primes = sieve(55555)
    
    ans = [i for i in primes if i % 10 == 3]
    print(*ans[:N])

if __name__ == '__main__':
    resolve()

Solution (Python):


n = int(input())


pn = [2, ]
A = 3000
for L in range(5, A):
    chk = True
    for L2 in pn:
        if L % L2 == 0:
            chk = False
    if chk:
        pn.append(L)


for i in pn:
    if i % 5 == 2:
        print(i, "", end="")
        n -= 1
    if n == 0:
        exit()

Solution (Python):
N=int(input())
import math
def isprime(x):
  for i in range(2,math.floor(math.sqrt(x))+2):
    if x%i==0:
      return False
      break
  return True

               
L=[]
one=11
while len(L)<N:
  if isprime(one):
    L.append(one)
  one+=10
print(*L)

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


n = int(input())
ans = []
is_prime = sieve_of_eratosthenes(55555)

for i in range(2, 55556):
    if is_prime[i] is True and i % 10 == 1:
        ans.append(i)
        if len(ans) == n:
            break

print(*ans)

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

MAX = 55555


def create_prime_list(n):
    if n < 2:
        return []
    prime_list = [2]
    x = 3
    while x <= n:
        flag = False
        for p in prime_list:
            if x < p ** 2:
                flag = True
                break
            if x % p == 0:
                break
        if flag:
            prime_list.append(x)
        x += 2
    return prime_list


def main():
    prime_list = create_prime_list(MAX)
    w = [x for x in prime_list if x % 5 == 1]
    print(*w[:N])
    

if __name__ == "__main__":
    main()

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

prime = [True]*nmax
prime[0] = prime[1] = False
for i in range(2, int(nmax**0.5)+1):
  if not prime[i]: continue
  for j in range(2*i, nmax, i):
    prime[j] = False

arr = []
for i in range(2, nmax):
  if not prime[i]: continue
  if i%10 == 3:
    arr.append(i)
    if len(arr) == n: break

print(*arr, sep=' ')

Solution (Python):
import sys

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

primes = set()
exists = set()
for i in range(2, 55555):
    if i in exists:
        continue
    primes.add(i)
    for j in range(i, 55555, i):
        if j in exists:
            continue
        exists.add(j)


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

print(*ans)

Solution (Python):
def primes(n):
    candidate = list(range(2, n+1))
    prime = []
    limit = n**0.5 + 1
    while True:
        p = candidate[0] 
        if limit <= p:
            prime.extend(candidate)
            break
        prime.append(p)

        candidate = [i for i in candidate if i % p != 0]
    return prime
N=int(input())
M=55555
L=primes(M)
L=[i for i in L if i%5==1]
S=L[:N]
S=list(map(str,S))
print(" ".join(S))

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


n = int(input())
ps = get_sieve_of_eratosthenes(55555)
ansl = []
for p in ps:
    if p%5 == 1:
       ansl.append(p) 

print(*ansl[:n])

Solution (Python):
import math

n=int(input())

def prime_check(x): 
    if x==2:
        return True
    elif x%2==0:
        return False
    else:
        limit=int(math.sqrt(x))
        for factor in range(3,limit+1,2):
            if x%factor==0:
                return False
        return True

temp=11
count=0
L=[]
while True:
    if prime_check(temp):
        L.append(temp)
        count+=1
    
    if count==n:
        break
    else:
        temp+=10

print(*L)

Solution (Python):
n=int(input())
lst=[]
d=[False for I in range(55556)]
for i in range(2,55555):
    if d[i]==False:
        lst.append(i)
        for j in range(i,55555,i):
            d[j]=True
ans=[]
for i in lst:
    if i%5==1:
        ans.append(i)
print(*ans[:n])

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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 power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


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)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
primes = set(range(2, 55555+1))
for i in range(2, int(55555**0.5+1)):    
    primes.difference_update(range(i*2, 55555+1, i))
primes=list(primes)
ans = []
for num in primes:
    if num % 5 == 1:
        ans.append(num)
print(*ans[:n], sep=' ')