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):
def is_prime(num):
    limit = int(num ** 0.5) + 1
    for i in range(2, limit):
        if num % i == 0:
            return False
    return True


n = int(input())
ans = [2, 7, 17]

for num in range(27, 55555, 10):
    if is_prime(num):
        ans.append(num)

    if len(ans) == n:
        break

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

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


n = int(input())
ans = [2]

for num in range(3, 55555, 2):
    if num % 5 == 2 and is_prime(num):
        ans.append(num)

    if len(ans) == n:
        break

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

Solution (Python):
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
p = []
for i in range(1,11111):
    n = 5*i + 1
    if is_prime(n):
        p.append(str(n))
N = int(input())
ans = p[:N]
print(' '.join(ans))

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

    def Eratosthenes(x: int) -> set:
        """x以下の素数の集合を返す"""
        import math
        sup = int(x)
        primes = {i for i in range(2, sup+1)}
        for i in range(2, int(math.sqrt(sup+1))+1):
            if i in primes:
                mul = 2
                while i*mul <= sup:
                    primes.discard(i*mul)
                    mul += 1
        return primes

    p = Eratosthenes(55555)
    for v in p.copy():
        if v % 5 != 1:
            p.discard(v)

    from itertools import combinations
    for i, v in enumerate(combinations(p, N)):
        if i == 0:
            print(*v)
            break


if __name__ == '__main__':
    main()

Solution (Python):
import math

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 = []
  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]
 
P = get_sieve_of_eratosthenes(55555)

answer = []
for p in P:
  if p % 5 == 1:
    answer.append(p)
    if len(answer) == N:
      print(*answer)
      exit()

Solution (Python):
mx=100000
p=[True]*(mx+10)
p[0]=p[1]=False
for i in range(2,mx+1):
  if p[i]==True:
    for j in range(i*i,mx+1,i):
      p[j]=False
A=[]
for i in range(1,mx+1):
  if p[i]==True and i%5==1:
    A.append(i)

N=int(input())
print(*A[0:N])

Solution (Python):
def prm(x):
  if x == 1:
    return False
  for i in range(2,x):
    if x%i == 0:
      return False
  else:
    return True
n=int(input())
ans=[]
for j in range(1,55551,5):
  if prm(j):
    ans.append(j)
    if len(ans) == n:
      break
print(*ans,sep=" ")

Solution (Python):






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

x=[str(i) for i in range(10,55556) if ((i%10==1) and (isPrime(i)))][:k]
print(" ".join(x))

Solution (Python):
p = [True] * 100010
p[0] = p[1] = False
for i in range(2, 100000):
    if p[i] == True:
        for j in range(2 * i, 100000, i):
            p[j] = False

n = int(input())
a = []
i = 6
while len(a) < n:
    if p[i]:
        a.append(i)
    i += 5

for i in a:
    print(i, end = " ")

Solution (Python):

import math


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

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

    
    return True


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

    
    return numbers


l = callIsPrime(20 ** 3)
ll = []
for i in range(len(l)):
    tmp = str(l[i])
    if tmp[-1] == '1':
        ll.append(l[i])



n = int(input())
ans_list = ll[:n]
for i in range(len(ans_list)):
    ans_list[i] = str(ans_list[i])
print(' '.join(ans_list))

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

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

l=list()
for i in range(6,55555,5):
  if is_prime(i):
    l.append(i)
    n-=1
  if n==0:
    print(*l)
    exit()

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=55555
a=int(input())
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)
b=[]
for i in primes:
    if i%5==3:
        b.append(i)

print(*b[:a])

Solution (Python):
n = int(input())
lis = []
for i in range(2, 10000, 5):
    now = 2
    flag = True
    while(now**2<=i):
        if i % now == 0:
            flag = False
            break
        now += 1
    if flag:
        lis.append(i)
for i in range(n):
    print(lis[i],end="")
    if i != n-1:
        print(" ", end="")
print("")

Solution (Python):

def primes(M):
    is_prime = [-1 for _ in range(M+1)]
    for m in range(2, M+1):
        if is_prime[m] == -1:
            is_prime[m] = 1
            l = 2
            while m*l <= M:
                is_prime[m*l] = 0
                l += 1
    primes = []
    for p in range(2, M+1):
        if is_prime[p] == 1:
            primes.append(p)
    return primes

N = int(input())

P = primes(55555)
A = []
for p in P:
    if p%5 == 2:
        A.append(p)
    if len(A) == N: break
print(' '.join([str(a) for a in A]))

Solution (Python):
n=int(input())
l=[]
d=1
def judge(p):
  for i in range(2,int(p**0.5+1)):
    if p%i==0:
      return False
  return True
cnt=0
while cnt<n:
  if judge(d*10+1):
    l.append(d*10+1)
    cnt+=1
  d+=1
print(*l)

Solution (Python):

N = int(input())     











sieved_number_set = set() 
ans = []

n = 55555


for i in range(2,n+1):
    if i not in sieved_number_set:
        
        exclude_list = [i*j for j in range(1,1+(n)//i)]
        sieved_number_set = sieved_number_set | set((exclude_list))
        
        
        str_i = str(i)
        if str_i[-1]=="1":
            ans.append(i)
            if len(ans)==N:
                break

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

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007


def A():
    return


def B():
    return


def C():
    return


def D():
    n = II()
    ans = []
    sosu = [2]
    i = 2
    while len(ans) != n:
        for k in sosu:
            if i % k == 0:
                i += 1
                break
        else:
            sosu.append(i)
            if i % 5 == 1:
                ans.append(i)
            i += 1
    for i in ans:
        print(i, end=" ")
    print()
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    D()

Solution (Python):
N=int(input())
P=[]
for i in range(1,11111):
  p=5*i+1
  hantei=True
  for j in range(2,int(p**0.5)+1):
    if p%j==0:
      hantei=False
  if hantei:
    P+=[p]

print(*P[:N])

Solution (Python):
import math

N = int(input())

prime = []
for i in range(2, 55556):
    flag = True
    for j in range(2, int(math.sqrt(i)) + 1):
        if i % j == 0:
            flag = False
            break
    if flag and i % 5 == 1:
        prime.append(i)

print(" ".join(map(lambda x: str(x), prime[:N])))

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    ans = []
    n = int(input().rstrip('\n'))
    for i in range(2, 10 ** 10):
        b = True
        for j in range(2, int(i ** 0.5) + 1):
            if i % j == 0:
                b = False
                break
        if b and i % 5 == 1:
            ans.append(i)
            if len(ans) == n:
                print(*ans)
                exit()


if __name__ == '__main__':
    solve()

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

def main():
    n = int(input())
    prime_ls = makePrimeChecker(55555)
    ans = []
    i = 2
    while 1:
        if len(ans)==n:
            break
            
        if prime_ls[i] and i%5==1:
            ans.append(i)
        else:
            pass
        i += 1
    for ans_ in ans:
        print(ans_,end=" ")
    print("\n")

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
p = []
def check(n):
  for i in range(2,int(n**0.5)+1):
    if n%i==0:
      return False
  return True

for i in range(2,55556):
  for j in range(2, int(i**0.5)+1):
    if i%j==0:
      break
  else:
    if i%5==1:
      p += [i]


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

Solution (Python):

import sys


def solve(N: int):
    
    

    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
    
    primes = sieve(55555)
    mod_primes = [p for p in primes if p%5==1]
    print(*mod_primes[:N])
    return


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

if __name__ == '__main__':
    main()

Solution (Python):
import math

n = int(input())


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


prime = callIsPrime(55555)

ans = []
for p in prime:
    if p % 5 == 1:
        ans.append(p)
        if len(ans) == n:
            break
for p in ans:
    print(p)

Solution (Python):
n=int(input())
a=[True]*55556
b=[]
a[0]=a[1]=False
p=0
for i in range(2,55556):
	if a[i]:
		b.append(i)
		for j in range(2*i,55556,i):
			a[j]=False
i=cnt=0
ans=[]
while cnt<n:
	if b[i]%5==3:
		ans.append(b[i])
		cnt+=1
	i+=1
print(*ans)

Solution (Python):
n=int(input())
fac=[True]*55556
fac[0]=False
fac[1]=False
for i in range(2,len(fac)):
  if fac[i]:
    nodiv=True
    for j in range(2,fac[i]):
      if fac[i]%j==0:
        nodiv=False
        break
    if not nodiv:
      fac[i]=False
    else:
      for j in range(i*2,len(fac),i):
        fac[j]=False

ans=[0]*n
ind=0
for i in range(len(fac)):
  if fac[i] and i%5==1:
    ans[ind]=i
    ind+=1
    if ind==n:
      break
print(*ans)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
import numpy as np 
import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

prime = [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, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173,
         179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
         283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
         419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 
         547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 
         661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 
         811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 
         947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 
         1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 
         1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 
         1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 
         1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 
         1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 
         1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 
         1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 
         2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 
         2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 
         2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 
         2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 
         2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 
         2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 
         3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 
         3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 
         3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 
         3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 
         3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 
         3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 
         4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 
         4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 
         4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 
         4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 
         4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 
         4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 
         5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 
         5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 
         5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531]

def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])

def main():
    n=inp()
    ans=[]
    index = 0
    while len(ans)<n:
        if prime[index]%5==1:
            ans.append(prime[index])
        index+=1
    print(*ans)
            
if __name__ == "__main__":
    main()

Solution (Python):
import math
prime = []
max_num = math.sqrt(55555)
data = [i + 1 for i in range(1, 55555)]
while True:
  p = data[0]
  if p >= max_num:
    prime += data
    break
  prime.append(p)
  data = [e for e in data if e % p != 0]
satisfy_prime = [p for p in prime if p % 5 == 1]

n = int(input())
print(" ".join([str(p) for p in satisfy_prime[:n]]))

Solution (Python):
N = int(input())
def get_sieve_of_eratosthenes(n):
    import math
    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]

ans = []
li = get_sieve_of_eratosthenes(55555)
for i in li:
  if i % 5 == 1:
    ans.append(i)
  if len(ans) >= N:
    break
print(*ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
import itertools

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

m = 55555
r = 5
N = INT()

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

prime_list = primes_for(m)


last_is_one = []
for prime in prime_list:
    if prime % 10 == 1:
        last_is_one.append(prime)

last_is_one.sort()

p_s = []
for p in last_is_one[:N]:
    p_s.append(str(p))

ans = " ".join(p_s)
print(ans)

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())
c = 1
d = 11
L = [2]
while c<n:
  if is_prime(d):
    L.append(d)
    c += 1
  d += 10
print(*L, sep=" ")

Solution (Python):
n1=int(input())
def sieve(n):
  l=[]
  prime=[True for i in range(n)]
  prime[0]=False
  prime[1]=False
  for i in range(1,n):
    if prime[i]:
      l.append(i)
      num=n//i
      for j in range(2,num):
        prime[j*i]=False
  return l
l=sieve(100000)
index=0
count=0
ans=""
while count<n1:
  if l[index]%5==1:
    ans+=str(l[index])+" "
    count+=1
  index+=1
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def prime(n):
    if n<=1: return []
    S=[1]*(n+1)
    S[0]=0; S[1]=0
    for i in range(2,n):
        if S[i]==0: continue
        for j in range(2*i,n+1,i):
            S[j]=0
    return [p for p in range(n+1) if S[p]]

def resolve():
    n=int(input())
    P=prime(55555)
    S=set()
    for p in P:
        if(p%5==1): S.add(p)
    print(*list(S)[:n])
resolve()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect_left
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

primaries = primes_for(55555)
primaries_mod_1 = [x for x in primaries if x%5==1]
print(*primaries_mod_1[:N])

Solution (Python):
primes = [2]
for p in range(3,55556,2):
    isPrime = True
    for q in primes:
        if q*q>p:break
        if p%q==0:
            isPrime = False
            break
    if isPrime: primes.append(p)

primes_1 = [p for p in primes if p%5==1]
print(*(primes_1[:int(input())]))

Solution (Python):



n = int(input())
prim = [1]*55556
prim[0] = 0
prim[1] = 0
for i in range(2,55556):
    for j in range(2,55556//i):
        prim[i*j] = 0
ans = [2]
for i in range(55556):
    if prim[i] and i%5==1:
        ans.append(i)
print(*ans[:n])

Solution (Python):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


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

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    if n > 1:
        _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


primes = [x for x, b in enumerate(eratosthenes(55556)) if b and x % 5 == 1]
n = int(input())
print(*primes[:n], sep=' ')

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    ans = []
    for i in range(2, 10 ** 10):
        if i % 5 == 1:
            b = True
            for j in range(2, int(i ** 0.5) + 1):
                if i % j == 0:
                    b = False
                    break
            if b:
                ans.append(i)
                if len(ans) == n:
                    print(*ans)
                    exit()


if __name__ == '__main__':
    solve()

Solution (Python):

m=int(input())
n = 55555
prime = {i for i in range(2,n)}
for i in range(2,n):
    if i in prime:
        for j in range(i*2,n,i):
            if j in prime:
                prime.remove(j)
                
prime.remove(2)
lists=[]
for j in prime:
    if j%15==1:
        lists.append(j)
A=lists[:m]
print(*A)

Solution (Python):

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

for i in prime_list:
    if i % 5 == 1:
        ans.append(i)
        count += 1
    if count == n:
        break
print(" ".join(map(str, ans)))

Solution (Python):
def Eratosthenes(n):

    dp = [False]*n
    dp[0] = dp[1] = True
    prime = []
    for i in range(2,n):
        if dp[i]:
            continue
        prime.append(i)
        for j in range(i*2,n,i):
          dp[j] = True
    return prime

N = int(input())
E = Eratosthenes(55555)
A = []
for e in E:
  if e % 5 == 1:
    A.append(e)
  if len(A) == N:
    break
print(*A)

Solution (Python):

N = int(input())

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

A = primes(5000) 
print(*A[:N])

Solution (Python):

N = int(input())

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

A = primes(5000) 
A.pop(0)
print(*A[:N])

Solution (Python):

N = int(input())

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

A = primes(5000) 
A.pop(0)
print(*A[:N])

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

n = int(input())
k = prime(1500)
for i in range(n):
    print(k[i], end=" ")

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

a = [13, 23, 43, 53, 73, 83, 103, 113, 163, 173, 193, 223, 233, 263, 283, 293, 313, 353, 373, 383, 433, 443, 463, 503, 523, 563, 593, 613, 643, 653, 673, 683, 733, 743, 773, 823, 853, 863, 883, 953, 983, 1013, 1033, 1063, 1093, 1103, 1123, 1153, 1163, 1193, 1213, 1223, 1283, 1303, 1373, 1423, 1433, 1453, 1483, 1493, 1523, 1543, 1553, 1583, 1613, 1663, 1693, 1723, 1733, 1753, 1783, 1823, 1873, 1913, 1933, 1973, 1993, 2003, 2053, 2063, 2083, 2113, 2143, 2153, 2203, 2213, 2243, 2273, 2293, 2333, 2383, 2393, 2423, 2473, 2503, 2543, 2593, 2633, 2663, 2683, 2693, 2713, 2753, 2803, 2833, 2843, 2903, 2953, 2963, 3023, 3083, 3163, 3203, 3253, 3313, 3323, 3343, 3373, 3413, 3433, 3463, 3533, 3583, 3593, 3613, 3623, 3643, 3673, 3733, 3793, 3803, 3823, 3833, 3853, 3863, 3923, 3943, 4003, 4013, 4073, 4093, 4133, 4153, 4243, 4253, 4273, 4283, 4363, 4373, 4423, 4463, 4483, 4493, 4513, 4523, 4583, 4603, 4643, 4663, 4673, 4703, 4723, 4733, 4783, 4793, 4813, 4903, 4933, 4943, 4973, 4993, 5003, 5023, 5113, 5153, 5233, 5273, 5303]

st = ""
for i in range(N-1):
    st += str(a[i]) + " "
st += str(a[N-1])
print(st)

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
    
a=[]
for i in range(55555):
	if i % 5 == 1:
		if is_prime(i):
			a.append(i)	
N=int(input())
for i in range(N):
	print(a[i], end=' ')

Solution (Python):
N=int(input())
count=0
PN=[]

Prime=[2]
for i in range(2,55555):
    for j in range(len(Prime)):
        if i%Prime[j]==0:
            break;
        else:
            if j==len(Prime)-1:
                Prime.append(i)
                if i%5==1:
                    PN.append(i)
                    count=count+1
        if count==N:
            break;
for i in range(N):
    print(PN[i],end=" ")

Solution (Python):




N = int(input())

a = [
    12959,
    14347,
    15511,
    51749,
    23819,
    26849,
    6089,
    27779,
    23339,
    13859,
    26699,
    18719,
    15149,
    5279,
    27689,
    10079,
    18089,
    15629,
    10139,
    51419,
    46889,
    41579,
    5519,
    29429,
    29879,
    1259,
    3929,
    13799,
    27179,
    3449,
    4409,
    32609,
    21269,
    44729,
    52769,
    10499,
    39209,
    42899,
    269,
    13709,
    509,
    3779,
    22619,
    15749,
    4349,
    51479,
    14879,
    39659,
    48449,
    3299,
    8849,
    40499,
    46829,
    45869,
    8039
]

print(*a[:N])

Solution (Python):



M=55555
m=int(M**0.5)+1

S=[ 0 for _ in range(M+1) ]


for i in range(2,m+1):
    for j in range(i*2,M+1,i):
        S[j]=1

N=input()
cnt=0
for i in range(2,M+1):
    if S[i]==0 and i%5==1:
        print i,
        cnt+=1
        if cnt==N:
            quit()