Problem:
 Score: 400 points    Problem Statement  Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the following conditions:   a_i  (1 \leq i \leq N) is a prime number at most 55  555 .  The values of a_1, a_2, ..., a_N are all different.  In every choice of five different integers from a_1, a_2, ..., a_N , the sum of those integers is a composite number.   If there are multiple such sequences, printing any of them is accepted.      Notes  An integer N not less than 2 is called a prime number if it cannot be divided evenly by any integers except 1 and N , and called a composite number otherwise.      Constraints   N is an integer between 5 and 55 (inclusive).         Input  Input is given from Standard Input in the following format:  N       Output  Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.        Sample Input 1 5      Sample Output 1 3 5 7 11 31  Let us see if this output actually satisfies the conditions. First, 3 , 5 , 7 , 11 and 31 are all different, and all of them are prime numbers. The only way to choose five among them is to choose all of them, whose sum is a_1+a_2+a_3+a_4+a_5=57 , which is a composite number. There are also other possible outputs, such as 2 3 5 7 13 , 11 13 17 19 31 and 7 11 5 31 3 .       Sample Input 2 6      Sample Output 2 2 3 5 7 11 13   2 , 3 , 5 , 7 , 11 , 13 are all different prime numbers.  2+3+5+7+11=28 is a composite number.  2+3+5+7+13=30 is a composite number.  2+3+5+11+13=34 is a composite number.  2+3+7+11+13=36 is a composite number.  2+5+7+11+13=38 is a composite number.  3+5+7+11+13=39 is a composite number.   Thus, the sequence 2 3 5 7 11 13 satisfies the conditions.       Sample Input 3 8      Sample Output 3 2 5 7 13 19 37 67 79

Solution (Python):
import itertools
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

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





def get_primes(max=None, count=None):
    """
    素数列挙
    昇順にソートされています
    https://qiita.com/Ishotihadus/items/73e107271275611f05f2
    :param int max:
    :param int count:
    """
    assert max or count
    if count:
        raise NotImplementedError()
    if max <= 1:
        return []

    primes = [2]
    sieve = [False for _ in range(max + 1)]
    p = 3
    while p <= max:
        primes.append(p)
        sieve[p] = True
        if p <= math.sqrt(max):
            for i in range(p * (p | 1), max + 1, p * 2):
                sieve[i] = True
        while p <= max and sieve[p]:
            p += 2

    return primes


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

is_prime = [False] * 55555 * 5
for p in get_primes(55555 * 5):
    is_prime[p] = True


def test(ans):
    for choices in itertools.combinations(ans, r=5):
        if is_prime[sum(choices)]:
            return False
    return True



ans = []
for p in get_primes(55555):
    if p % 5 == 1:
        ans.append(p)

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

Solution (Python):












def ret_erators(N: int):
    
    is_prime = [True] * (N + 1)

    
    is_prime[0] = False
    is_prime[1] = False

    for i in range(2, int(N**0.5) + 1):
        if is_prime[i]:
            j = i * 2  
            while j < N + 1:
                is_prime[j] = False
                j += i
    return is_prime


is_prime = ret_erators(55555)


candi = []
for i in range(55555):
    n = i * 5 + 1
    if n > 55555:
        break
    if is_prime[n]:
        candi.append(n)


print(*candi[:int(input())])

Solution (Python):

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

n = int(input())

count = 0
ans = []
for i in range(11, 5001, 10):
    if is_primary(i):
        ans.append(i)
        count += 1
        if count == n:
            break

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

Solution (Python):

n = int(input())
i = 11
cnt = 0
ans = []
while cnt < n:
  for j in range(2,int(i**.5)+1):
    if i % j == 0:
      i += 10
      break
  else:
    cnt += 1
    ans.append(i)
    i += 10
print(' '.join(list(map(str,ans))))

Solution (Python):

n = 55555


is_prime = [True]*(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]]

N=int(input())

ans=[]
cnt=0
for i in range(len(table)):
    if table[i]%5==1:
        ans.append(table[i])
        cnt+=1
    if cnt==N:
        break
    
        
print(' '.join(map(str, ans)))

Solution (Python):

import math
import heapq
import bisect
import numpy as np
from collections import Counter


N = int(input())
THS = 55555

sieve = [0]*(THS+1)
prime_list = []
for i in range(2,THS+1):
    if sieve[i] == 0:
        prime_list.append(i)
        j = i
        while j <= THS:
            sieve[j] = 1
            j += i

ans = [[] for _ in range(4)]
for p in prime_list:
    ans[p%5-1].append(p)

for a in ans:
    if len(a) >= N:
        print(*a[:N])
        break

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

x = [0] * (55555 + 10)
ans = []
for i in range(2, 55556):
    if x[i] == 0:
        t = i
        while t < 55556:
            x[t] = 1
            t += i
        if i % 5 == 1:
            ans.append(i)
            if len(ans) == N:
                break
print(*ans)

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    n = int(input())
    p = sieve_of_eratosthenes(55555)
    ans = []
    for i in p:
        if i % 5 == 1:
            ans.append(i)
    print(*ans[:n],sep = " ")
if __name__ == "__main__":
    main()

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    n = int(input())
    p = sieve_of_eratosthenes(55555)
    ans = []
    for i in p:
        if i % 5 == 1:
            ans.append(i)
    print(*ans[:n],sep = " ")

if __name__ == "__main__":
    main()

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

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

ans = []
for i in range(11, 55556, 10):
    if isprime(i):
        ans.append(i)
        N -= 1
    if N == 0:
        break
print(*ans)

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    n = int(input())
    p = sieve_of_eratosthenes(55555)
    res = []
    for i in p:
        if i % 5 == 3:
            res.append(i)
    print(*res[:n],sep = " ")
if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

def main():

    isprime = [1 for i in range(60000)]
    primes = []
    for i in range(2, 55556):
        if isprime[i] == 1:
            if i % 5 == 1:
                primes.append(i)
            for j in range(1, 55556//i + 1):
                isprime[j * i] = 0


    n = getN()
    print(*primes[:n])




if __name__ == "__main__":
    main()

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue


Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): 
    n = int(input())
    p = sieve_of_eratosthenes(55555)
    res = []
    for i in p:
        if i % 5 == 1:
            res.append(i)
    print(*res[:n],sep = " ")
if __name__ == "__main__":
    main()

Solution (Python):
import math
N = int(input())
ans = []
ans_len = 1
ans.append(2)
for i in range(1, 55556):
    flag = 0
    if i % 10 != 7:
        continue
    for j in range(2, math.ceil(math.sqrt(i))):
        if i % j == 0:
            flag = 1
            break
    if flag == 0:
        ans.append(i)
        ans_len += 1
        if ans_len == N:
            break

print(*ans, sep=" ")

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
            """
            bool(not False)はTrueになる
            """
        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_numbers = primes(55555)
ans = []
for p in prime_numbers:
    if p % 5 == 1:
        ans.append(p)
print(" ".join(map(str, ans[:N])))

Solution (Python):
n=int(input())
pri=[1]*(10**7)
ans=[]
for i in range(2,55556):
  if pri[i]>0:
    if i%5==1:
      ans.append(i)
    for k in range(1,55556//i+1):
      pri[i*k]=0
print(' '.join(map(str,ans[:n])))

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


def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1


ans = []
for i in range(2, 55556):
    if len(ans) == n:
        print(*ans)
        exit()

    if is_prime(i) and i % 5 == 1:
        ans.append(i)

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

def eratosthenes(n):
    res = []
    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(n+1):
        if is_prime[i]:
            res.append(i)
    return res

prime = eratosthenes(55555)

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

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

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


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    
    N = Scanner.int()
    ans = []
    for i in range(2, 55555+1):
        if Math.isPrime(i) and (i-1) % 5 == 0:
            ans.append(i)
            if len(ans) == N:
                break
    print(*ans,sep=" ")


if __name__ == "__main__":
    main()

Solution (Python):

import re
import math
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline

mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="number"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True

 

 

P=[]
for a in get_primes(55555):
    if a%5==1:P.append(a)
N=int(input())
print(" ".join(list(map(str,P[0:N]))))

Solution (Python):
from math import sqrt
M = 55556
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
N = int(input())
ans = []
c = 0
for i in range(1,M):
    if i%5 == 1 and p[i]:
        ans.append(i)
        c += 1
    if c == N:
        break
print(" ".join(map(str,ans)))

Solution (Python):

from itertools import combinations


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

def make_prime_nums(N):
    
    prime_tf = [True for _ in range(N+1)]
    prime_tf[0] = False
    prime_tf[1] = False
    for i in range(N+1):
        if prime_tf[i]:
            if eratosthenes(i):
                for j in range(i*2, N+1, i):
                    prime_tf[j] = False
    primes = [i for i in range(N+1) if prime_tf[i] and i % 5 == 1]
    return primes
def divisor(N):
    
    divs = []
    for i in range(2, int(N**0.5)+1):
        if N % i == 0:
            divs.append(i)
            divs.append(N//i)
    return divs

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

Solution (Python):
def main():
    n=int(input())
    a=[]
    s=[]
    t=0
    for k in range(3,55556):
        b=k
        for j in s:
            if k%j==0:
                b=0
        if b==k:
            s.append(k)
            if k % 5 == 1:
                if t < n:
                    a.append(k)
                    t += 1
                else:
                    break
     
    print(*a)
    
    
    
main()

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

n=int(input())
a=0
for i in range(55555):
  if primes(2000)[i]%5==1:
    print(primes(55555)[i],end=" ")
    a=a+1
  if a==n:
    break
print()

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

import math


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

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

    
    return True


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

    
    return numbers


x=callIsPrime(55555)
v=[]
for i in range(len(x)):
    if x[i]%5==1:
        v.append(x[i])
        if len(v)==n:
            break
print(*v)

Solution (Python):
is_prime=[True]*55556
is_prime[0]=is_prime[1]=False

def solve(N):
    ans=[]
    for n in range(2,55556):
        if not is_prime[n]: continue
        if  n%5==1:
            ans.append(n)
        if len(ans)==N: break
        for m in range(n*n,55556,n): is_prime[m]=False
    return ans

N=int(input())
print(' '.join(map(str,solve(N))))

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

from itertools import combinations
N=int(input())

prime_list=primes(55555)
id=4
ans=[prime_list[i] for i in range(len(prime_list)) if prime_list[i]%5==2]

print(" ".join(map(str,ans[: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]]
    
primes = primes(55555)
primes2 = [i for i in primes if i%5 == 1]
print(*primes2[:N])

Solution (Python):
def main():
    n = int(input())
    p = [2]
    for i in range(2,55556):
        for j in p:
            if i%j == 0:
                break
        else:
            p.append(i)
    l = []
    for i in p:
        if i%5 == 1:
            l.append(i)
    ans_list = [str(i) for i in l[:n]]
    print(" ".join(ans_list))
    
if __name__ == '__main__':
    main()

Solution (Python):
def prime_table(N):
    P = [False]*2+[True]*(N-1)
    for i in range(2,int(N**.5)+1):
        if P[i]: P[2*i::i] = [False]*(N//i-1)
    return P

N=int(input())
print(*[i for i, p in enumerate(prime_table(55555)) if p and i % 10 == 1][:N])

Solution (Python):
def primes(MAX):
    from math import sqrt
    prime = []
    limit = sqrt(MAX)
    data = [i + 1 for i in range(1, MAX)]
    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 = list(filter(lambda n: n % 5 == 1, primes(55555)))[0:N]
print(" ".join(map(str, Ps)))

Solution (Python):
from math import sqrt
N = int(input())
dp = [[0] for i in range(N+1)]
dp[5] = [11,31,41,61,71]
def is_prime(x):
    if x == 1:
        return False
    if x % 2 == 0:
        if x == 2:
            return True
        else:
            return False
    for i in range(3,int(sqrt(x))+1,2):
        if x % i == 0:
            return False
    return True

for i in range(5,N):
    tmp = dp[i][-1]+10

    for j in range(tmp,55556,10):

        if is_prime(j):
            dp[i+1] = dp[i]+[j]
            break
        
print(*dp[N])

Solution (Python):
n=int(input())
a=55555
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]]
b=primes(a)
ans=[]
for i in range(len(b)):
  if b[i]%5==2:
    ans.append(b[i])
    if len(ans)==n:
      break
print(*ans)

Solution (Python):
P = [1 for _ in range(55556)]
P[0]=0
P[1]=0
for i in range(2,int(55555*0.5)+1):
    for j in range(i*i,55556,i):
        P[j] = 0
Q = []
for i in range(2,55556):
    if P[i]==1:
        Q.append(i)
imax = len(Q)
N = int(input())
A = [2]
for i in range(3,imax):
    if str(Q[i])[-1]=="3":
        A.append(Q[i])
print(*A[:N])

Solution (Python):
n = int(input())
prime = [3, 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]
ans = prime[1:n+1]
print(*ans)

Solution (Python):


def eratosthenes(mx):
    array = [1 for _ in range(mx)]
    array[0] = array[1] = 0
    for i in range(4, mx, 2):
        array[i] = 0
    for i in range(3, mx, 2):
        if not array[i]:
            continue
        for j in range(i+i, mx, i):
            array[j] = 0
    return array

n = int(input())
prime = [i for i, flag in enumerate(eratosthenes(55555 + 1)) if flag and i % 10 == 3]
ans = prime[1:n+1]
print(*ans)

Solution (Python):
def get_primenumber(N):
    
    prime_list = [2]
    
    for num in range(3,N+1,2):
        
        if all( num % prime != 0 for prime in prime_list):
            prime_list.append(num)


    return prime_list

def main():
    while True:
      number = int(input())
      if number > 1:
        break
      else:
        print("2以上の自然数を入力してください")
    nums = get_primenumber(10000)
    count = 0
    for i in range(10000):
        if nums[i] % 5 == 1:
            print(nums[i], end=' ')
            count += 1
        if count == number:
            break



if __name__ == "__main__":
    main()

Solution (Python):

def isPrime(p):
    for i in range(2, int(p**0.5)+1):
        if p % i == 0:
            return False
    return True
n=int(input())
p=[]
ans=[]
for i in range(2,55556):
    if isPrime(i):
        p.append(i)

for i in range(len(p)):
    if len(ans)<n:
        if p[i]%5==1:
            ans.append(p[i])
    else:
        break

print(*ans)

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

n = 55555
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)


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

print(*ans[:N])

Solution (Python):
N = int(input())
n = 55555
primes = set(range(3, n+1, 2))|set([2])
for i in range(3, int(n**0.5+1)):
    primes.difference_update(range(i*3, n+1, i*2))
primes=list(primes)
a = []
for i in primes:
  if i%10==1:
    a.append(i)
    if len(a)==N:
      break
print(*a)

Solution (Python):








N = int(input())
def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        
        data = [d for d in data if d%p != 0]
ps = getprime(55555)
l = []
for p in ps:
    if p % 5 == 1:
        l.append(p)
ans = l[:N]
print(*ans)

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

l=[]
for i in range(11,55556)[::10]:
    l.append(i)
    for num in range(2,-(-int((i**0.5)//1))+1):
        if i%num==0:
            l.pop(-1)
            break
print(*l[:N])

Solution (Python):
N = int(input())
prime = []


def isPrime(n):  
    if n == 0 or n == 1:
        return False
    if n == 2:
        return True
    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, 55555 + 1):
    if isPrime(i) and i % 5 == 1:
        prime.append(i)


print(*prime[:N], sep=" ")

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

Solution (Python):
data = []
now = 1
while len(data) < 55:
    now += 10
    t = True
    for i in range(2,now-1):
        if now %i == 0:
            t = False
            break
    if t:
        data.append(now)

n = int(input())
print(*data[:n])

Solution (Python):
import sys
from math import floor, sqrt

def prime_nums(n):
    sieve = set(range(2, n + 1))
    non_prime = set(range(2 * 2, n + 1, 2))
    sieve -= non_prime
    for i in range(3, floor(sqrt(n)) + 1, 2):
        if i in sieve:
            non_prime = set(range(i * 2, n + 1, i))
            sieve -= non_prime
    return sieve

ps = prime_nums(55555)

cand = []
for p in ps:
    if p % 5 == 1:
        cand.append(p)


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

def main():
    return cand[:n]  

if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def is_prime(num):
    """ 素数判定 """
    from math import sqrt

    if num < 2: 
        return False
    if num in [2, 3, 5]: 
        return True
    if num % 2 == 0 or num % 3 == 0 or num % 5 == 0:
        return False
    
    prime = 7
    step = 4
    num_sqrt = sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return False
        prime += step
        step = 6 - step
    return True

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