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):
from math import sqrt
lst=[]
def prime(x,lst):
    n=int(sqrt(x))
    for i in range(2,n+1):
        if x%i==0:
            return lst
    if x%5==1:
        lst.append(x)

for i in range(2,55555):
    prime(i,lst)
m=int(input())
y=''
for i in range(m):
    y+=str(lst[i])+' '
print(y)

Solution (Python):

primeN=[]
for i in range(2,3000):
    for j in range(2,i+1):
        if i%j==0:
            if i==j:
                primeN.append(i)
            else:
                break
primeN_5=[]
for i in primeN:
    if i%5==2:
        primeN_5.append(i)
n=int(input())
c=[]
for i in range(n):
    c.append(str(primeN_5[i]))
print(" ".join(c))

Solution (Python):

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]

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

Solution (Python):
N=input()

def prime(n):
    seq = list(range(2, n))
    while len(seq) > 0:
        prime = seq.pop(0)
        yield prime
        seq = [i for i in seq if not i % prime == 0]


s=list(prime(55556))

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

for i in a: print i,

Solution (Python):

def is_prime(n):
    if n < 2: return False
    if n == 2: return True
    if n % 2 == 0: return False

    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1

    return True


N = int(input())


l = []

n = 2
while len(l) < N:
    if is_prime(n) and n % 5 == 1:
        l.append(n)
    n += 1

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

Solution (Python):
def abc096_dx():
    n = int(input())
    primes = [2, 3]

    for num in range(5, 55555, 2):
        is_prime = True
        for i in range(1, len(primes)):
            if primes[i] ** 2 > num:
                break
            if num % primes[i] == 0:
                is_prime = False
                break
        if is_prime:
            primes.append(num)

    ans = []
    for num in primes:
        if num % 5 == 1:
            ans.append(str(num))
        if len(ans) == n:
            break
    return " ".join(ans)
print(abc096_dx())

Solution (Python):
F = range(2, 55556)
primes=[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]
N = int(raw_input())
i = 1
oks = []
while len(oks) < N:
  p = i*10+1
  j = 0
  isPrime = True
  while primes[j]*primes[j] <= p:
    if p % primes[j]==0:
      isPrime = False
      break
    j += 1
  if isPrime:
    oks.append(p)
  i += 1
ans = str(oks[0])
for a in  oks[1:]:
  ans += ' {}'.format(a)
print ans

Solution (Python):
import math

def nth_prime(N):
    primes = [2]
    n = 1
    while(len(primes) < N):
        n += 2
        m = int(math.sqrt(n))
        for p in primes:
            if p > m:
                primes.append(n)
                break
            if n % p == 0:
                break
    return primes[-1]

def main():
    N = int(input())
    i = 1
    a = []
    while len(a) < N:
        p = nth_prime(i)
        if p % 5 == 1:
            a.append(nth_prime(i))
        i += 1
    s = ' '.join(str(i) for i in a)
    print(s)

if __name__ == '__main__':
    main()

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

ans = []

def is_prime(x):
    for y in range(3,int(x**(1/2))+2,2) :
        if x%y == 0 :
            return False
    return True

cur = 11
while len(ans) < n :
    if is_prime(cur) :
        ans.append(cur)
    cur += 10

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

Solution (Python):
import numpy as np


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 = np.array(primes(55555))
five_one_list = prime_list[prime_list % 5 == 1]

choice = map(str, five_one_list[:N])
ans = ' '.join(choice)

print(ans)

Solution (Python):
import math
prime = [True]*(55555)
prime[0],prime[1] = False,False
for i in range(2, int(math.sqrt(55555))+1):
	if not prime[i]: continue
	for j in range(i*2,55555,i): prime[j] = False
n = int(input())
x,num = [2,7,17,37,47],57
while len(x)!=n:
	 num+=10
	 if prime[num]: x.append(num)
for i in x[:n-1]: print(i,end=" ")
print(x[-1])

Solution (Python):
import itertools
import math


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


N = int(input())
primes = get_primes(55555)
ans = []
i = 4

while len(ans) < N:
    p = primes[i]
    
    if p % 5 == 1:
        ans.append(p)

    i += 1

print(*ans)

Solution (Python):
N = int(input())
counter = 0
primes = [2, 3]
for n in range(5, 2000 + 1, 2):
    isprime = True
    for i in range(1, len(primes)):
        if primes[i] ** 2 > n:
            break
        if n % primes[i] == 0:
            isprime = False
            break
    if isprime:
        primes.append(n)
ans = [i for i in primes if i % 5 == 1]
print(" ".join(map(str, ans[:N])))

Solution (Python):
n=int(input())
p=[3,13,23,43,53,73,103,113,163,173,193,223,233,263,283,293,313,353,373,383,443,463,503,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]
for i in range(n):
    print(p[i],end=' ')

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

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

for i in range(3,55555):
    if hantei(i) and i % 5 == 1:
        prime.append(i)
    if len(prime) >= 55:
        ans = ""
        for s in range(N):
            if s != N-1:
                ans += str(prime[s]) + " "
            else:
                ans += str(prime[s])
        print(ans)
        quit()

Solution (Python):


import math
import sys
import itertools
import numpy as np

n = int(input())

a=[2,3]
for i in range(5,1400,2):
    maxi = int(math.sqrt(i)) +1
    isprime = 1
    for j in range(3,maxi,2):
        if (i % j) == 0:
            isprime = 0
            break
    if isprime == 1:
        a.append(i)



b=[]
for i in a:
    if i % 5 == 1:
        b.append(i)



for i in range(n):
    print(b[i], end=' ')
print()

Solution (Python):
import math
n = int(input())
MAX = 55555
primes = [i for i in range(MAX)]
primes[1] = 0
for prime in primes:
    if prime > math.sqrt(MAX): break
    if prime == 0: continue
    for non_prime in range(2 * prime, MAX, prime): primes[non_prime] = 0
primes = [prime for prime in primes if prime != 0]
count = 0
index = 0
ans = []
while(count < n):
    all_list = []
    if(primes[index] % 10 == 1):
        ans.append(primes[index])
        count += 1
    index += 1
a = ""
for x in ans:
    a += str(x) + " "
print(a.rstrip(" "))

Solution (Python):



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

N = int(input())
sosu = []
for candidate in range(2, 55555):
    if is_sosu(candidate) and candidate % 5 == 1:
        sosu.append(candidate)
        if len(sosu) >= N:
            break
print(' '.join([str(s) for s in sosu]))

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

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 = ni()
ans = [0]*n

for i in range(n):
    for j in range(1,55556):
        if j % 5 == 1 and is_prime(j) == True and not j in ans:
           ans[i] = j
           break
for i in ans:
    print(i, end=" ")

Solution (Python):
prime = [2]
pr5 = []
fl = False
for i in range(3,5555):
    for j in prime:
        if i % j == 0:
            fl = True
    if fl == False:
        prime.append(i)
        if i % 5 == 1:
            pr5.append(i)
    fl = False
n = int(input())
ans = []
for i in range(n):
    ans.append(str(pr5[i]))
print(" ".join(ans))

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

def Eratosthenes(N):
    li = [i for i in range(2, N+1)]
    serial = []
    amari1 = []
    while li:
        li.sort()
        num = li[0]
        if num % 5 == 1:
            amari1.append(num)
        serial = [k * num for k in range(1, N//num + 1)]
        li = list(set(li) - set(serial))
    return(amari1)
        
ansList = list(map(str, Eratosthenes(1500)))
print(" ".join(ansList[0: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]]

p_list = primes(55555)
p5_list = [i for i in p_list if i%5 == 1]
out = ' '.join(map(str, p5_list[:n]))
print(out)

Solution (Python):
p = []
def is_prime_trial_division(n):
    if n < 2:
        return False
    else:
        for i in range(2, n):
            if i * i > n:
                break
            elif n % i == 0:
                return False
        return True
for i in range(2,55555):
    if is_prime_trial_division(i):
        p.append(i)
N = int(input())
s = ""
a = []

for i in p:
    if i%5==1:
        a.append(i)
    if len(a)==N:
        break

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

Solution (Python):
import math

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]
  
n = int(input())
prime_nums = primes(55555)
ans = []
for p in prime_nums:
  if str(p)[-1] == '1':
    ans.append(p)
  if len(ans) == n:
    for a in ans:
      print(a, end = ' ')
    quit()

Solution (Python):
import sys,collections,math,random,itertools;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()

import numpy
def primesfrom2to(n):
    """ Input n>=6, Returns a array of primes, 2 <= p < n """
    sieve = numpy.ones(n/3 + (n%6==2), dtype=numpy.bool)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1|1
            sieve[       k*k/3     ::2*k] = False
            sieve[k*(k-2*(i&1)+4)/3::2*k] = False
    return list(numpy.r_[2,3,((3*numpy.nonzero(sieve)[0][1:]+1)|1)])

lis = primesfrom2to(55555)
lis2 = []
for e in lis:
    if e % 5 == 1:
        lis2.append(str(e))
ans = random.sample(lis2,n)
print(" ".join(ans))

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

import math

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]

a = primes(55555)
ans = []
for i in range(len(a)):
    tmp = a[i]
    if tmp % 5 == 1:
        ans.append(a[i])
        if len(ans) == n:
            break
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 and prime%5 == 1]

r = primes(5555)
result = []
for i in range(n):
    result.append(r[i])
l = list(map(str,result))
print(' '.join(l))

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


def p_amari(start):
    num = start
    while num < 55555:
        if is_prime3(num) and num % 5==1:
            return num
        num += 1

A = []
t = 2
for j in range(N):
    ADD = p_amari(t)
    A.append(ADD)
    t = ADD + 1

moted = map(str, A)
print(" ".join(moted))

Solution (Python):
a  = [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]
N = int(input())
print(" ".join(list(map(str,a[:N]))))

Solution (Python):
def isPrime(x):
	for i in range(2,min(x,236)):
		if x%i == 0:
			return False
	return True
n,a,p = int(input()),[],2
while n > 0:
	if isPrime(p):
		a.append(str(p))
		n -= 1
	p += 5
print(" ".join(a))

Solution (Python):
def d_five_five_everywhere(N):
    def prime_table(n):
        
        table = [True for _ in range(n + 1)]
        i = 2
        while i**2 <= n:
            if table[i]:
                j = i + i
                while j <= n:
                    table[j] = False
                    j += i
            i += 1
        ret = [i for i in range(n + 1) if table[i] and i >= 2]
        return ret
    prime = prime_table(55555)  
    prime_match = []  
    series_length = 0
    for p in prime:
        if p % 5 == 1:
            prime_match.append(p)
            series_length += 1
        if series_length == N:
            break
    ans = ' '.join(map(str, prime_match))
    return ans

N = int(input())
print(d_five_five_everywhere(N))

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