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 sieve_of_eratosthenes(n):
    pl = [i for i in range(2, n + 1)] 
    i=0
    p = pl[0]
    while p**2<=n:
        pl = [pl[j] for j in range(len(pl)) if pl[j]%p!=0 or j<=i]
        i+=1
        p=pl[i]
    return pl

pl=sieve_of_eratosthenes(55555)

N=int(input())

i=0
ans = []
while len(ans)<N:
    if pl[i]%5==1:
        ans.append(pl[i])
    i+=1

print(*ans)

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

l=primes(10000)
x=0;i=0
while x<n:
  if l[i]%10==1:
    print(l[i])
    x+=1
  i+=1

Solution (Python):
n=int(input())
def get_sieve_of_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]
sosuu=get_sieve_of_eratosthenes(55555)
sosuu_5=[]
for i in sosuu:
    if i%5==1:
        sosuu_5.append(i)
ans=''
for i in sosuu_5[:n]:
    ans=ans+str(i)+' '
print(ans)

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

n = int(input())
x = 11
ans = []
while(True):
    if is_prime(x) and x % 5 == 1:
        ans.append(x)
        if len(ans) == n:
            break
    x += 2
print(*ans)

Solution (Python):
def check(n):
    i = 2
    while i*i<=n:
        if n%i==0:
            return False
        i+=1
    return True
n = int(input())
a = [2]
i = 6
while i<=55555:
    if check(i):
        a.append(i)
    i+=5
for i in range(n):
    print(a[i],end=' ')

Solution (Python):
n=int(input())
l=[]

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

for i in range(2,55555):
  if prime(i) is True and i%5==1:
    l.append(i)
  if len(l)>=n:
    break
print(" ".join(map(str,l)))

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
B=[False]*2+[True]*(55554)
mid=55555//2
for i in range(2,mid):
    if B[i]:
        for j in range(2*i,55556,i):
            B[j]=False
c=0
for i in range(2,55556):
    if c==n:
        break
    else:
        if B[i] and i%5==1:
            print(i,end=" ")
            c+=1
print()

Solution (Python):

import sys

def is_prime(n):
  if n == 2 or n == 3: return True
  if n < 2 or n%2 == 0: return False
  if n < 9: return True
  if n%3 == 0: return False
  r = int(n**0.5)
  f = 5
  while f <= r:
    if n%f == 0: return False
    if n%(f+2) == 0: return False
    f +=6
  return True  

def solve(N: int):

    cnt = 0
    for i in range(1,55556):
        if is_prime(i) and i % 5 == 1:
            print(i)
            cnt += 1
            if cnt == 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):
def primes(n):
  is_prime = [True] * (n + 1)
  is_prime[0] = False
  is_prime[1] = False
  for i in range(2, int(n**0.5) + 1):
    if not is_prime[i]:
      continue
    for j in range(i * 2, n + 1, i):
      is_prime[j] = False
  return [i for i in range(n + 1) if is_prime[i]]
n=int(input())
P=primes(55555)
Ans=[]
i=0
while len(Ans)<n:
  if P[i]%5==1:
    Ans.append(P[i])
  i+=1
print(*Ans)

Solution (Python):
n=int(input())
p=[1]*55556
i=2
while n:
    if p[i]:
        for j in range(i+i,55556,i):
            p[j]=0
        if i%10==1:
            print(i,end=' ')
            n-=1
    i+=1

Solution (Python):
n=int(input())
p=[1]*55556
i=2
while n:
    if p[i]:
        for j in range(i+i,55556,i):
            p[j]=0
        if i%10==1:
            print(i,end=' ')
            n-=1
    i+=1

Solution (Python):
N = int(input())
nums = [[i, True] for i in range(55555+1)]

for i in range(2, 55555+1):
    if nums[i][1]:
        if nums[i][0] % 5 == 1:
            print(nums[i][0])
            N -= 1
        for j in range(i, 55555+1, nums[i][0]):
            nums[j][1] = False

    if not N:
        break

Solution (Python):

import sys

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

def solve(N: int):
    primes = []
    for i in range(3, 55556):
        if is_p(i) and i % 5 == 3:
            primes.append(i)
        if len(primes) >= N:
            break
    
    print(' '.join([str(p) for p in primes]))
    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):
N = int(input())
ans = [2]
N -= 1

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

next_val = 3
for _ in range(N):
    while not is_prime(next_val):
        next_val += 5
    ans.append(next_val)
    next_val += 5

print(*ans)

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = [1]
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if (self.parent[i] == i):
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if i < j:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n = intin()

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



if __name__ == '__main__':
    main()

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
    
N = int(input())
p = list(filter(lambda x:x%10 == 1, primes(55555)))
for i in range(N):
    print(p[i], end=" ")

Solution (Python):
def PRIME(N):
    LIM = int(N**0.5)+2
    for i in range(2, LIM):
        if N%i == 0:
            return False
    return True

n = int(input())
p = []
ans = ""
for i in range(2, 55556):
    if i%5 == 1:
        if PRIME(i):
            p.append(i)

for j in range(n):
    ans += str(p[j])+" "

print(ans)

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

def primes(n):
    from math import sqrt
    p = [1] * (n + 1)
    for x in range(2, int(sqrt(n)) + 1):
        if p[x]:
            p[x * 2:n + 1:x] = [0] * ((n - x) // x)
    return (i for i in range(2, n + 1) if p[i])

i = 0
for n in primes(55555):
    if n % 5 == 1:
        print(n)
        i += 1
        if i == N:
            break

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

a = [-1,-1,0]+[0]*(n-2)
i = 2
while i * i <= n:
    if a[i] == 0:
        a[i] = 2
        b = i * 2
        while b <= n:
            a[b] = -1
            b += i
    i += 1

one = [x for x in range(2,n+1) if a[x] != -1 and x % 5 == 1]
print(*one[0:N])

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

p=primes(55555)
ans=[]
for i in p:
    if i%5==3:
        ans.append(i)
for i in ans[:N]:
    print(i,end=' ')

Solution (Python):

import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def prime_table(n):
    t = [True] * (n + 1)
    t[0] = False
    t[1] = False

    i = 2
    while i * i <= n:
        for ii in range(2 * i, n + 1, i):
            t[ii] = False
        i += 1
    return [x for x, i in enumerate(t) if i == True]


def solve(N: int):
    res = []
    for p in prime_table(55555):
        if p % 5 == 1:
            res.append(p)
            if len(res) == N:
                break
    return res


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    result = solve(N)
    if isinstance(result, Iterable):
        result = ' '.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):

import sys, itertools
N=input()

P={}
primes=[]
def is_prime(x):
    if x==1:return False
    if x==2:return True        
    if x%2==0:return False
    if x==3:return True
    i=3
    while i*i<=x:
        if x%i==0:return False
        i+=2
    return True

def is_ok(seq):
    for s in itertools.combinations(seq,5):
        if P[sum(s)]: return False
    return True


for i in range(1, 55556*6):
    P[i] = is_prime(i)
primes=[x for x,f in P.iteritems() if f and x<=55555]

cand=[]
for p in primes:
    if p%10==1:cand.append(p)
ans=cand[:N]
print(" ".join(map(str,ans)))

Solution (Python):
n = int(input())
res = []
num = 6
while len(res) < n:
    num += 5
    if all(num%i != 0  for i in range(2,int(num**0.5)+1)):
        res.append(num)
print(*res)

Solution (Python):
import math
def prime(n): 
    lst = [2]
    for i in range(3, n+1):
        flag = True
        for j in lst:
            if j > math.sqrt(i):
                break
                
            if i % j == 0:
                flag = False
                break
        if flag:
            lst.append(i)
    return lst
N = int(input())
primes = prime(55555)
ans = []
cnt = 0
for p in primes:
    if p % 5 == 1:
        ans.append(p)
        cnt += 1
        if cnt == N:
            break
print(*ans)

Solution (Python):
def prime(n): 
    lst = [2]
    for i in range(3, n+1):
        flag = True
        for j in lst:
            if i % j == 0:
                flag = False
                break
        if flag:
            lst.append(i)
    return lst
N = int(input())
primes = prime(55555)
ans = []
cnt = 0
for p in primes:
    if p % 5 == 1:
        ans.append(p)
        cnt += 1
        if cnt == N:
            break
print(*ans)

Solution (Python):
def prime(n):
    if n<2:
        return []
    primes=[]
    for i in range(2, n+1):
        if all(i%j!=0 for j in primes):
            primes.append(i)
    return primes
primes=prime(55555)
n=int(input())
a=[]
for p in primes:
    if len(a)==n:
        break
    if p%5==1:
        a.append(str(p))
print(' '.join(a))

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

Solution (Python):
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


def get_primes(max=None, count=None):
    """
    素数列挙
    昇順にソートされています
    https://qiita.com/Ishotihadus/items/73e107271275611f05f2
    :param int max:
    :param int count:
    :return:
    """
    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(input())
PRIMES = get_primes(max=55555)

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

Solution (Python):
import sys
import math 
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()
N = ni()
import numpy as np

def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum
pn = seachPrimeNum(10000)
res=[]
for i in pn:
    if("1" == str(i)[-1]):
        res.append(i)

print(*res[:N])

Solution (Python):
def primes(m):
    import math

    a = list(range(2, m))
    limit = math.ceil(math.sqrt(m))
    ps = []

    while True:
        p = a[0]
        if limit < p:
            return ps + a

        ps.append(p)

        a = [ai for ai in a if ai % p != 0]


primes = primes(10000)
n = int(input())

arr = []
while len(arr) < n:
    p = primes.pop()
    if p % 5 == 1:
        arr.append(p)

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

Solution (Python):

import sys
import itertools


class cPrimes:
    def __init__(self, N):
        self.N = N
        self.L = N // 96 + 1
        self.sieve()
    
    def sieve(self):
        self.bits = [ -1 ] * self.L
        for p in itertools.takewhile(lambda p: p * p < self.N,
                            itertools.islice(self.enumerate(), 2, None)):
            k0 = p // 3
            for k in range(k0 + p * 2, self.N // 3 + 1, p * 2):
                self.erase_bit(k)
            for k in range(-k0 - 1 + p * 2, self.N // 3 + 1, p * 2):
                self.erase_bit(k)
    
    def enumerate(self):
        yield 2
        yield 3
        k0 = 1
        for m, B in enumerate(self.bits):
            for k in range(k0, 32):
                if ((B >> k) & 1) == 1:
                    yield m * 96 + k * 3 + 1 + (k & 1)
            k0 = 0
    
    def is_prime(self, n):
        if n < 4:
            return n >= 2
        else:
            q, r = divmod(n, 6)
            if r == 1:
                k = q >> 4
                l = (q & 15) << 1
                return ((self.bits[k] >> l) & 1) == 1
            elif r == 5:
                k = q >> 4
                l = ((q & 15) << 1) + 1
                return ((self.bits[k] >> l) & 1) == 1
            else:
                return False
    
    def erase_bit(self, k):
        m = k >> 5
        l = k & 31
        if l != 31:
            self.bits[m] &= ~(1 << l)
        else:
            self.bits[m] &= ~(-1 << 31)

def solve(N: int):
    cp = cPrimes(55555)
    result = []
    for p in cp.enumerate():
        if p % 5 == 2:
            result.append(str(p))
        if len(result) == N:
            break
    print(' '.join(result))
    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 numpy as np

is_prime = np.ones(2000,dtype = np.int64)
is_prime[:2] = 0

for p in range(2,2000):
  if p > 150:
    break
  if is_prime[p]:
    is_prime[p*p::p] = 0

primes = is_prime.nonzero()[0]
primes = primes[primes%5 == 1]

n = int(input())

ans = ' '.join([str(x) for x in primes[:n]])
print(ans)

Solution (Python):
import numpy as np
import sys,collections as cl
def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum

Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

n = int(input())

a = seachPrimeNum(55555)
aa = []
for i in range(len(a)):
	if a[i] % 5 == 1:
		aa.append(a[i])

print(" ".join(map(str,aa[:n])))

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

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table
q,p=sieve(55555)
ans=0
q=[]
for i in p:
    if i%5==1:
        q.append(i)
for i in range(N):
    print(q[i],end=" ")

Solution (Python):
import math

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

N=int(input())

prime = []
for i in range(55555):
    if is_prime(i+1):
        prime.append(i+1)

prime_5 = []
for i in range(len(prime)):
    if prime[i] % 5 == 1:
        prime_5.append(prime[i])

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

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def make_prime_list(lower:int, upper:int) -> list:
    
    
    if lower < 0:
        raise ValueError("lowerは0以上でなければいけません。(lower:{})".format(lower))

    elif upper <= lower:
        raise ValueError("upperはlowerより大きい数でなければいけません。\
                         (lower:{}, upper:{})".format(lower,upper))
    
    
    isPrime = [True]*upper
    primeList = []
    
    
    if upper <= 2:
        return primeList
    
    
    isPrime[0] = False
    isPrime[1] = False
    
    
    n = 2
    while n**2 <= upper:
        if isPrime[n]:
            res=2*n
            while res<upper:
                isPrime[res] = False
                res += n
                
        n += 1
    
    
    for n in range(lower,upper):
        if isPrime[n]:
            primeList.append(n)
        
    return primeList

n = ni()

prime_list = make_prime_list(0, 55555)

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

Solution (Python):

import sys
INF = float("inf")


def eratosthenes_sieve(n):
    table = [0] * (n + 1)
    prime_list = []

    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1

    return prime_list


def solve(N: int):
    primes = eratosthenes_sieve(55555)

    
    myprimes = [p for p in primes if p % 10 == 1]

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

    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):
N = int(input())

prime = [2]
for i in range(3, 55556):
    flag = 1
    for j in prime:
        if i % j == 0:
            flag = 0
            break
    if flag == 1:
        prime.append(i)

ans = []
for i in prime:
    if i % 5 == 1:
        ans.append(i)
print(" ".join(map(str, ans[:N])))

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

prime = [2]
for i in range(3, 55556):
    flag = 1
    for j in prime:
        if i % j == 0:
            flag = 0
            break
    if flag == 1:
        prime.append(i)

ans = []
for i in prime:
    if i % 5 == 1:
        ans.append(i)
print(" ".join(map(str, ans[:N])))

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

Solution (Python):
import math

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

m = 5555
xs = []
for i in range(1, m):
    if prime(i*10 + 1):
        xs.append(i*10+1)
        if len(xs) > 55:
            break

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

Solution (Python):

import sys
import math


def primes(n: int):
    d = [True for i in range(n+1)]
    for i in range(2, n+1):
        if d[i]:
            for j in range(2, math.floor(n/i)+1):
                d[j*i] = False
    result = []
    for i in range(2, n+1):
        if d[i] and i % 5 == 1:
            result.append(i)
    return result


def solve(N: int):
    p = primes(55555)
    result = p[0:N]
    resultStr = ""
    isFirst = True
    for i in result:
        if not isFirst:
            resultStr += " "
        resultStr += str(i)
        isFirst = False
    print(resultStr)
    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):
def primes_upto(m):
    _l = list(range(2, m+1))
    primes=[]
    while _l:
        p = _l[0]
        primes.append(p)
        _l=[n for n in _l if n%p]
    return primes

primes = primes_upto(55555)
A = [p for p in primes if p%5==1]

N=int(input())
print(' '.join([str(a) for a in A[:N]]))

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

N = int(input())
upper = 55555
p_flag = [True]*(upper+1)
p_flag[0] = p_flag[1] = False
prime = []

for i in range(2, upper+1):
    if p_flag[i]:
        prime.append(i)
        for j in range(2*i, upper+1, i):
            p_flag[j] = False

ans = []
cnt = 0
for i in prime:
    if i % 5 == 1:
        ans.append(i)
        cnt += 1
    if cnt == N:
        break

print(*ans)

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

primes = [2,3,5,7]
ans = []
for n in range(11,55555+1):
    for p in primes:
        if n % p == 0:
            break
    else:
        primes.append(n)
        if n%5==1:
            ans.append(n)
            if len(ans) >= N:
                break
print(" ".join(map(str,ans)))

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

Solution (Python):
import sys
import math
def Sieve_of_Eratosthenes(N):
    prime=set(i for i in range(2,N+1))
    for i in range(2,math.ceil(N**0.5)+1):
        tmp=set()
        for j in prime:
            if j>i and j%i==0: tmp.add(j)
        for j in tmp:
            prime.remove(j)

    return(prime)

N=int(input())
prime=Sieve_of_Eratosthenes(55555)
ans=[[] for i in range(5)]
for i in prime:
    ans[i%5].append(i)

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

Solution (Python):
N = int(input())
prime = [] 
for i in range(11,1500,10):
    for j in range(2,int(i**0.5)+1): 
        if i%j == 0:
            break
    else:
        prime.append(i)
print(*prime[:N])

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


def prime(k):
    p = [True] * (k+1)
    p[0] = False
    p[1] = False
    for i in range(2, k+1):
        if p[i]:
            for j in range(i*2, k+1, i):
                p[j] = False
    return [i for i in range(k + 1) if p[i]]


def mod5(px):
    return [p for p in px if p % 5 == 1]


px = prime(2000)
qx = mod5(px)

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

Solution (Python):
import math

N = int(input())

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

primes = [str(i) for i in range(2, 55555+1) if i%5==1 and isPrime(i)]
print(' '.join(primes[0:N]))

Solution (Python):
N=int(input())
sosu=[2,3,5,7]
A=[]
M=11
while len(A)<N:
  if all(M%i!=0 for i in sosu):
    sosu.append(M)
    if M%5==1:
      A.append(M)
  M+=2
print(*A)

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


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


primeList = SieveofEratosthenes(55555)
primeList = [p for p in primeList if p % 5 == 1]
ans = str(primeList[0])
for i in range(1, N):
    ans = ans + ' ' + str(primeList[i])
print(ans)

Solution (Python):
import math

def is_prime(x):
    if x < 2:
        return False
    else:
        t = int(math.sqrt(x)) + 1
        for n in range(2, t):
            if x % n == 0:
               return False
        return True


n = int(input())

cnt = 0
ans = []
for num in range(2, 55555):
    if is_prime(num) and num % 5 == 1:
        cnt += 1
        ans.append(num)

    if cnt == n:
        break

print(*ans)

Solution (Python):
from math import sqrt,floor
N=int(input())
L=[]
for i in range(2,55556):
    if i%10!=1:
        continue
    flag=True
    for j in range(2,int(sqrt(i))+4):
        if i%j==0:
            flag=False
    if flag:
        L.append(i)
print(' '.join(map(str,L[:N])))

Solution (Python):
L=[	7151,8111,8741,8431,9241,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]
print(' '.join(map(str,L[:int(input())])))

Solution (Python):
era = [1]*55556

era[0] = era[1] = 0
for i in range(2,int(55556**0.5)+1):
    if( era[i] == 1):
        for j in range(i*2,55556,i): era[j] = 0

v = [0]*5
n = int(input())
for i in range(55556):
    if(era[i] and i%5 == 1):
        print(i, end=" ")
        n -= 1
        if(n == 0): break
print()

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

x=[i for i in range(2,55556)if is_prime(i)and i%5==1]
print(*x[:int(input())])