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

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

ans = []
i = 1
while len(ans)<N:
  tmp = i*10 +1
  i += 1
  flag = 0
  for j in range(3, tmp//3+1):
    if tmp%j == 0:
      flag = 1
      break
  if flag == 0:
    ans.append(tmp)

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

Solution (Python):
import math

def is_prime(x):
    if x < 2: return False 
    if x == 2 or x == 3 or x == 5: return True 
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False 

    
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True
	

N = int(input())
count = 0
a_list = []

for i in range(5550):
	a = 10 * i + 1
	if is_prime(a):
		a_list.append(a)
		count += 1
		if count == N:
			break

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

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

prime=[]
num=list(range(3,55555,2))
p=2
while p<int(55555**(1/2)):
    prime.append(p)
    for j, ni in enumerate(num):
        if ni%p==0:
            del num[j]
    p=num.pop(0)
prime.extend(num)

mod5=[]
for p in prime:
    if p%5==1:
        mod5.append(p)
ans=list(map(str , mod5[:n]))
print(' '.join(ans))

Solution (Python):
a =[11,31,41,61,71,101,131,151,181,191,211,241,251,271,311,401,431,461,911,941,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1741,1801,1811,1831,1861,1901,1931,1951,2011,2111,2141,2221,2311,2351,2411,2441,2731,2791,2801,2851,2861,2971,3001,3011,3041,3061,3121,3181,3191]
n = int(input())
for i in range(n):
	print(a[i],end = " ")

Solution (Python):

isPrime=[1 for i in range(0,55556)]
Primes=[]
isPrime[0]=0
isPrime[1]=0
for i in range(2,55556):
  if isPrime[i]==1:
    Primes.append(i)
    for j in range(2,int(55556/i)):
      isPrime[j*i]=0

li=[]
for i in Primes:
  if i%5==1:
    li.append(i)
ans=''
for i in range(0,int(input())):
  if i==0:
    ans+=str(li[i])
  else:
    ans+=' '+str(li[i])
  
print(ans)

Solution (Python):
import itertools as it
def erat():
    D = {9:3, 25:5}
    yield from [2, 3, 5]
    MASK = [1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0]
    MODULOS = (1, 7, 11, 13, 17, 19, 23, 29) 

    for q in it.compress(
            it.islice(it.count(7), 0, None, 2),
            it.cycle(MASK)):
        p = D.pop(q, None)
        if p is None:
            D[q*q] = q
            yield q
        else:
            x = q + 2*p
            while x in D or (x%30) not in MODULOS:
                x += 2*p
            D[x] = p


n = int(input())
l = 0
ans = []
for p in erat():
    if p % 5 == 1:
        ans.append(p)
        l += 1
        if l >= n:
            break
print(*ans)

Solution (Python):
N = int(input())
def get_prime_list(n):
    L = list(range(2,n+1))
    for i in range(2,int((n+1)**0.5)):
        if i not in L:
            continue
        L = [j for j in L if j <= i] + [j for j in L if j > i and j % i != 0]
    return L
L = [i for i in get_prime_list(55555) if i % 5 == 1]
print(*L[:N])

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    ans = []
    ps = []
    n = 1
    while True:
        n += 2
        for p in ps:
            if n % p == 0:
                break
        else:
            ps.append(n)
            if n % 5 == 1:
                ans.append(n)
                if len(ans) >= N:
                    return ' '.join(map(str, ans))


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()

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

def prime_check(x):
    for i in range(2,x):
        if x%i==0:
            return False
    return True
ans=[]
for i in range(11,55555,10):
    if prime_check(i):
        ans.append(i)
        n-=1
    if n==0:
        break


print(*ans)

Solution (Python):
def simple_is_prime(n):
    if n == 1:
        return False
    for i in range(2, n):
        if n%i==0:
            return False
    return True

N = int(input())
ans = []
for i in range(31, 55555, 30):
    if simple_is_prime(i):
        ans.append(i)
        N -= 1
    if N == 0:
        break
print(*ans)

Solution (Python):
from itertools import count, islice

def eratosthenes():
    d = {}
    for q in count(2):
        p = d.pop(q, None)
        if p:
            x = next(x for x in count(q + p, p) if x not in d)
            d[x] = p
        else:
            yield q
            d[q*q] = q

n = int(input())

ones = (prime for prime in eratosthenes() if prime % 10 == 1)
n_ones = islice(ones, n)
print(' '.join(map(str, n_ones)))

Solution (Python):
import math

N = int(input())

def is_prime(n):
    return all(n%i != 0 for i in range(2, int(math.sqrt(n)+1)))

n = 0
k = 1

while True:
    if is_prime(5*k+1):
        print(5*k+1, end="")
        n += 1
        if n == N:
            print("")
            break
        else:
            print(" ", end="")
    k += 1

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


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

for i in range(31,55556,30):
    if isprime(i):
        if i != 31:print(" ", end="")
        print(i ,end="")
        N -= 1
    if N==0:
        break
print()

Solution (Python):
import math

n = int(input())

def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False

    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

A = []
for a in range(11, 55555, 10):
    if is_prime(a):
        A.append(a)
        if len(A) == n:
            break
print(' '.join(map(str, A)))

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


M = 55560
prime=[True]*M
prime[0]=False
prime[1]=False
ans =[]
for i in range(2,M):
    if prime[i]:
        for j in range(2,(M-1)//i+1):
            prime[i*j]=False
    if i%10 ==1 and prime[i]:
        ans.append(i)
        Q-=1
    if Q==0:
        break
print(' '.join(map(str, ans)))

Solution (Python):
from itertools import *
n=range(55555);a=list(n);a[1]=0
for i in range(2,233):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))

cnt = 0
ans = []
N = int(input())
for x in p:
    if x%5 == 2:
        ans += [x]
        cnt += 1
        if cnt == N: break
print(*ans)

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

Solution (Python):
import math

def primes():
    a = 55555
    primes = [i for i in range(a)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(a):
            break
        if prime == 0: continue
        for non_prime in range(2 * prime, a, prime):
            primes[non_prime] = 0
    return [prime for prime in primes if prime != 0]

N = int(input())
k = 0
p = primes()
i = 0
while k < N:
    if p[i] % 5 == 1:
        print(p[i], end = ' ')
        i += 1
        k += 1
    else:
        i += 1
print()

Solution (Python):
import random

def is_prime3(q,k=50):
    q = abs(q)
    
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1

    
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        
        while t != q-1 and y != 1 and y != q-1:
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

N = int(input())
s=[0]*N
len = 0
for i in range(11,55555,5):
    if (is_prime3(i)):
        s[len]=i
        len =len+1
        if len == N:
            break
print(' '.join(map(str,s)))

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

def eratos(end):
  is_prime = [True]*end

  is_prime[0] = is_prime[1] = False

  primes=[]

  for i in range(2, end):
    if is_prime[i]:
      primes.append(i)
      for j in range(2*i, end, i):
        is_prime[j] = False

  return primes


primes=eratos(55555)

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



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

Solution (Python):
def primes(m):
    res=[]
    a=[True for i in range(m)]
    a[0]=a[1]=False
    for i in range(2,m):
        if a[i]:
            if i%5==1:
                res.append(i)
            times=2
            while i*times<m:
                a[i*times]=False
                times+=1
    return res

N=int(input())
prime=primes(55555)
for num in prime[:N]:
    print(str(num)+" ",end="")
print()

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

def prepare_prime(N):
    s = 0
    memo = [0 for _ in range(N)]
    for i in range(2, N):
        if s + 2 >= N:
            break

        p = i
        if memo[i] == 0:
            if i % 5 == 1:
                primes.append(i)
            while p < N:
                if memo[p] == 0:
                    memo[p] = 1
                    s += 1
                p += i
    return

prepare_prime(55555)

for idx in range(N):
    print(primes[idx + 2], end=' ' if idx < N-1 else '\n')

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

prime = [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(' '.join(map(str, prime[:n])))

Solution (Python):

import math

def so(x):
    if x % 2 == 0:
        return False
    max = int(math.sqrt(x))
    for i in range(3, max + 1, 2):
        if x % i == 0:
            return False
    return True

n = int(input())

finds = []
i = 2
while len(finds) < n:
    x = 5 * i - 1
    if so(x):
        finds.append(x)
    i += 1

print(*finds)

Solution (Python):
import math
N = int(input())
result = []
count = 0
i = 2


def isPrime(x):
    if x == 1:
        return False
    else:
        for i in range(2, x):
            if x % i == 0:
                return False
        return True


while True:
    n = 5 * i + 1
    if isPrime(n):
        result.append(n)
        count += 1
    if count == N:
        break
    i += 1

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

Solution (Python):
def prime(n,s):
    import math
    l = []
    sum=0
    for i in range(n):
        while True:
            flag = True
            for i in range(2, int(math.sqrt(s))+1):
                if s % i == 0:
                    flag = False
                    break
            if flag is True and s % 10 == 1:
                l.append(s)
                s += 1
                sum+=s
                break
            s += 1
    if sum%2==1:
        print(sum)
    nf=False
    for i in range(2, int(math.sqrt(sum))):
        if sum % i == 0:
            nf = True
            break
    if nf is True :
        return l
    else:
        return None
if __name__ == '__main__':
    N=int(input())
    s=11
    while True:
        l=prime(N,s)
        if l is not None:
            break
        else:
            s+=1
    for i in l:
        print("%d "%i, end="")

Solution (Python):
N = int(input())
cnt = 0
list1 = []
for i in range(2, 55555):
    for j in range(2, i+1):
        if i % j == 0 and i % 5 == 1:
            if i == j:
                cnt += 1
                list1.append(str(i))
            else:
                break
    if(cnt >= N):
        break

anslist = []


str = ' '.join(list1)
print(str)

Solution (Python):
from math import *
n = int(input())
ps = set(range(2, 55556))
for i in range(2, floor(sqrt(55555) + 1)):
    if i in ps:
        k = 2
        while(i*k <= 55555):
            if i*k in ps:
                ps.remove(i*k)
            k += 1
ans = []
i = max(ps)
while len(ans) < n and i <= 55555:
    if i in ps:
        ans.append(i)
    i -= 25
print(*ans)

Solution (Python):
from math import *
n = int(input())
ps = set(range(2, 55556))
for i in range(2, floor(sqrt(55555) + 1)):
    if i in ps:
        k = 2
        while(i*k <= 55555):
            if i*k in ps:
                ps.remove(i*k)
            k += 1
ans = []
i = max(ps)
while len(ans) < n and i <= 55555:
    if i in ps:
        ans.append(i)
    i -= 5
print(*ans)

Solution (Python):
import math

n = int(input())


def primes(x):
    if x < 2:
        return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x):
            break
        if prime == 0:
            continue
        for non_prime in range(2 * prime, x, prime):
            primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


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

print(' '.join([str(x) for x in ans]))

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


def is_prime(n):
    for i in range(1, n):
        if i != 1 and n % i == 0:
            return False
    return True


def prime_numbers():
    num = 5
    while True:
        is_num_prime = is_prime(num)
        if is_num_prime and num % 5 == 1:
            yield num
        num += 1


prime_gene = prime_numbers()
ans = [next(prime_gene) for _ in range(N)]
print(*ans)

Solution (Python):
from itertools import count
import math

def gen_prime():
    yield 2
    for i in count(3, 2):
        isPrime = True
        for j in range(3, int(math.sqrt(i)+1), 2):
            if i % j == 0:
                isPrime = False
                break
        if isPrime:
            yield i


n = int(input())
cn = 0

for p in gen_prime():
    if(p > 55555):
        break
    if(str(p)[-1] == '1'):
        print(p, end='')
        cn += 1
        if n == cn:
            print()
            break
        else:
            print(' ', end='')

Solution (Python):
k = int(input())
l = [2, 7, 17, 37, 47, 67, 97, 107, 127, 137, 157, 167, 197, 227, 257, 277, 307, 317, 337, 347, 367, 397, 457, 467, 487, 547, 557, 577, 587, 607, 617, 647, 677, 727, 757, 787, 797, 827, 857, 877, 887, 907, 937, 947, 967, 977, 997, 1087, 1097, 1117, 1187, 1217, 1237, 1277, 1297]
print(" ".join(map(str,l[0:k])))

Solution (Python):
N = int(input())
lis = [i for i in range(2,55555)]
primes = []
p=1
while(p*p < 55555):
  p = lis.pop(0)
  if p%5==1:primes.append(p)
  for num in lis:
    if num%p == 0: lis.remove(num)
while(len(primes)<=56):
  p = lis.pop(0)
  if p%5==1:primes.append(p)

print(' '.join(map(str, primes[:N])))

Solution (Python):


import math
N = int(input())



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

    return [prime for prime in primes if prime != 0]



def isPrime(x):
    if x < 2:
        return False
    if x == 2 or x == 3 or x == 5:
        return True  
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0:
        return False
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0:
            return False
        prime += step
        step = 6 - step
    return True


def calcFiveFivePrimes(N):
    primes = calcPrimes(2000)
    fiveFivePrimes = [prime for prime in primes if prime % 5 == 1]
    return fiveFivePrimes[:N]


print(" ".join(map(str, calcFiveFivePrimes(N))))

Solution (Python):


n = int(input())



def gen_prime():
    primes = []
    n = 2
    while True:
        is_prime_flag = True
        for p in primes:
            if n % p == 0:
                is_prime_flag = False
                break
        if is_prime_flag:
            primes.append(n)
            yield n
        n += 1

MAX_N = 55555

ns = []

for p in gen_prime():
    if p > MAX_N or len(ns) >= n:
        break

    if p % 5 == 1:
        ns.append(p)

ans = " ".join(map(str, ns))


print(ans)

Solution (Python):
from math import *
n = int(input())
ps = set(range(2, 55556))
for i in range(2, floor(sqrt(55555) + 1)):
    if i in ps:
        k = 2
        while(i*k <= 55555):
            if i*k in ps:
                ps.remove(i*k)
            k += 1
ans = []
i = 2
while len(ans) < n and i <= 55555:
    if i in ps:
        ans.append(i)
    i += 5
print(*ans)

Solution (Python):
import math

x=55555


L=math.floor(math.sqrt(x))







Primelist=[i for i in range(x+1)]

Primelist[1]=0

for i in Primelist:

    
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0
Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0]


Ans=[]

i=0
count=0

while count<=55:
    if Primes[i]%10==1:
        Ans=Ans+[Primes[i]]
        count+=1
        i+=1
    else:
        i+=1
    

N=int(input())

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

print(Ans[N])

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

def isPrime(target):
    for i in range(2, target):
        if target % i == 0:
            return False
    return True

for i in range(11, 55555, 5):
    if isPrime(i):
        ps.append(i)
        if len(ps) == n:
            break

print(*ps)

Solution (Python):
from math import sqrt, floor, ceil
from itertools import combinations


N = int(input())


def is_prime_num(num):
    num_sqrted = floor(sqrt(num))
    for i in range(2, num_sqrted + 1):
        if num % i == 0:
            return False
    else:
        return True

a_set = set()
while len(a_set) < N:
    for i in range(11, 55555, 10):
        if i in a_set:
            continue
        elif not is_prime_num(i):
            continue
        else:
            a_set.add(i)
            break

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

Solution (Python):
n = int(input())
d=[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]

x=[]
for i in range(n):
    x.append(str(d[i]))
k=' '.join(x)
print(k)

Solution (Python):



from math import sqrt, ceil



def sosu_list(N):
    temp = [True]*(N+1)
    temp[0] = temp[1] = False
    for i in range(2, ceil(sqrt(N+1))):
        if temp[i]:
            temp[i+i::i] = [False]*(len(temp[i+i::i]))                            
    primes = [ n for n in range(N+1) if temp[n] ]
    return primes

P = sosu_list(55555)


P = [i for i in P if i % 5 == 1]


N = int(input())


for i in range(N):
	print("{} ".format(P[i]),end ="")