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):
lol = [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, 1471, 1481, 1511, 1531]
a = int(input())

ans = ''
for i in range(a):
    ans = ans + str(lol[i]) + ' '

print(ans)

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

P=[i*2+3 for i in range(700)]
ans=[]
for i in P:
    n=2
    while i*n <= 1400:
        if i*n in P:
            P.remove(i*n)
        n += 1

for j in P:
    if j % 5 == 2:
        ans.append(j)
        
print(*ans[:N])

Solution (Python):
import sys

N = int(input()) 

def prime_judge(N):
    if N % 2 == 0 or N % 3 ==0:
        return False
    for i in range(4,N):
        if N % i == 0:
            return False
            break
    if N % 5 == 1 :
        return True
    else: False

a = []
n = 0
p = 2

while True:
    if prime_judge(p):
        if len(a) == N:
            a2 = [str(i) for i in a]
            print(" ".join(a2))
            sys.exit()
        a.append(p)
    p += 1

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

l = [i for i in range(55556)]
l[1] = 0
for i in l[1:]:
    if i > math.sqrt(55556): break
    if i == 0 :continue
    for j in range(2*i,55556,i): l[j] = 0

prime = [i for i in l if (l != 0 and (i - 3)%10 == 0)]
print(" ".join(map(str,prime[:N])))

Solution (Python):
import math

def main():
    
    N = int(input())
    MAX = 55555
    
    
    
    prime = [2]
    for num in range(3,MAX):
        cand = 2
        while cand < int(math.sqrt(num))+1:
            if num % cand == 0:
                break
            cand += 1
        if cand==int(math.sqrt(num))+1:
            prime.append(num)

    
    prime_five = []
    for pr in prime:
        if pr%5 == 1:
            prime_five.append(pr)

        
    
    answer = prime_five[:N]
    answer = [str(pr) for pr in answer]
    print(" ".join(answer))


if __name__ == "__main__":
    main()

Solution (Python):
def is_prime(n):
    i = 2
    while i*i <= n:
        if n%i==0:
            return False
        i+=1
    return True
N = input()
ans = []
for i in xrange(6,55555,5):
    if is_prime(i):
        ans.append(i)
        N -= 1
    if N == 0:
        break
print(' '.join(map(str,ans)))

Solution (Python):

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



N = int(input())
i = 0
temp = 0
List = []
while(i < N):
    judge = temp * 5 + 1
    if(isPrime(judge)):
        List.append(judge)
        i +=1
    temp += 1
print(' '.join(map(str,List)))

Solution (Python):
def is_prime(q):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False
    return pow(2, q - 1, q) == 1


if __name__ == '__main__':
    n = int(input())
    prime_list = []

    for i in range(int(55555 / 5)):
        if is_prime(i * 5 + 4):
            prime_list.append(i * 5 + 4)
    print(" ".join(map(str, prime_list[:n])))

Solution (Python):
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

def sieve2(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if(s[i] and i%5==2)]

print(" ".join(map(str,sieve2(55555)[:int(input())])))

Solution (Python):
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

def sieve2(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if(s[i] and i%5==2)]

n = int(input())
a = sieve2(55555)
ans=a[:n]
print(" ".join(map(str,ans)))

Solution (Python):
MAX_N = 55555

p = [True] * (MAX_N + 1)
p[0] = False
p[1] = False

for i in range(2,MAX_N + 1):
	if p[i] == True:
		for j in range(2 * i, MAX_N + 1, i):
			p[j] = False

prime = []
for i in range(2,MAX_N + 1):
	if p[i] == True and len(prime) < MAX_N:
		prime.append(i)



N = int(input())

res = []
for i in range(len(prime)):
	if prime[i] % 5 == 1 and len(res) < N:
		res.append(prime[i])

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

Solution (Python):
import sys

def getPrimes():
    primes = [2, 3]
    for n in range(5, 55555, 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)
    return primes

n = int(raw_input())

primes = getPrimes()
primes5n1 = [p for p in primes if p%5 == 1]
print ' '.join(map(str, primes5n1[:n]))

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

Solution (Python):
n = int(input())
primes = []
for i in range(11, 1500, 10):
    isPrime = True
    for k in range(2, 236):
        if k ** 2 > i:
            break
        elif i % k == 0:
            isPrime = False
            break
    if isPrime:
        primes.append(i)
print(" ".join(map(str, primes[:n])))

Solution (Python):

N=int(input())
s=[2,3,5]
ans=[]
for i in range(7,55555):
    for j in s:
       if i%j==0:
           break
       if j>i**(0.5):
           
           s.append(i)
           
           if i%5==1:
               ans.append(i)
           break
           
    if len(ans)==N:
        break
    
for i in range(N):
    print(ans[i],end=" ")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

class Prime():
    def __init__(self, n):
        self.M = m = int(math.sqrt(n)) + 10
        self.A = a = [True] * m
        a[0] = a[1] = False
        self.T = t = []
        for i in range(2, int(math.sqrt(m)) + 1):
            if not a[i]:
                continue
            t.append(i)
            for j in range(i*i,m,i):
                a[j] = False

    def is_prime(self, n):
        return self.A[n]

    def division(self, n):
        d = collections.defaultdict(int)
        for c in self.T:
            while n % c == 0:
                d[c] += 1
                n //= c
            if n < 2:
                break
        if n > 1:
            d[n] += 1
        return d.items()

    def sowa(self, n):
        r = 1
        for k,v in self.division(n):
            t = 1
            for i in range(1,v+1):
                t += math.pow(k, i)
            r *= t
        return r

def main():
    n = I()
    pr = Prime((55555*5) ** 2)
    prs = [c for c in range(2,55555) if pr.is_prime(c) and c%5==2]
    return ' '.join(map(str, prs[:n]))



print(main())

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


def create_prime_table(n):
    list = [True for _ in range(n + 1)]
    i = 2
    while i * i <= n:
        if list[i]:
            j = i + i
            while j <= n:
                list[j] = False
                j += i
        i += 1

    table = [i for i in range(n + 1) if list[i] and i >= 2]
    return table


prime = create_prime_table(55555)
cnt = 0
nine = []
for idx, i in enumerate(prime):
    if (i % 100) == 9:
        nine.append(i)
print(*nine[:n])

Solution (Python):
import array
import itertools


def sieve_of_eratosthenes(end, typecode="L"):
    assert end > 1
    
    
    
    is_prime = array.array("B", (True for i in range(end)))
    
    is_prime[0] = False
    is_prime[1] = False
    
    primes = array.array(typecode)
    
    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 = sieve_of_eratosthenes(55555)


n = int(input())
ret = []
count = 0
for _ in range(n):
    while(True):
        if primes[count] % 5==1:
            ret.append(primes[count])
            count += 1
            break
        count += 1
print(" ".join(map(str, ret)))

Solution (Python):
N = int(input())
prime = [False]*2 + [True]*55554
for i in range(2, 55556):
  if prime[i]:
    prime[2*i::i] = [False]*(55555//i-1)

arr = []
for i in range(11, 55556):
  if prime[i] and i % 10 == 1:
    arr.append(str(i))
print(' '.join(arr[:N]))

Solution (Python):
import math

N = int(input())

def find_desired_prime(n):
    primenums = []
    i = 2
    while True:
        isprime = True
        for j in range (2, math.ceil(math.sqrt(i)) + 1):
            if (i % j == 0):
                isprime = False
                break
        if isprime and i % 5 == 1:
            primenums.append(i)
        if len(primenums) >= n:
            break
        i += 1
    
    return primenums

print(' '.join(str(res) for res in find_desired_prime(N)))

Solution (Python):
def isPrime(x):
    if(x % 2 == 0):
        return False
    for i in range(3, min(x,236), 2): 
        if(x % i == 0):
            return False
    return True

n, a, p = int(input()), [], 11
while(n):
    if(isPrime(p)):
        a.append(str(p))
        n -= 1
    p += 10
print(" ".join(a))

Solution (Python):
s=['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 ','1307 ']
for i in range(int(input())):
    print(s[i],end="")
print("\n")

Solution (Python):
N=int(input())
ss=[2,3,5]
ans=[]
for i in range(7,55555):
    for j in ss:
        if i%j==0:
            break
        if j>i**(0.5):
            ss.append(i)
            if i%5==1:
                ans.append(i)
            break
    if len(ans)==N:
        break
for i in range(N):
    print(ans[i],end=" ")

Solution (Python):
import math
n = int(input())
def prime(i):
    if i < 2:
        return False
    for j in range(2,int(math.sqrt(i))+1):
        if i % j == 0:
            return False
    return True

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

Solution (Python):
import math

prime = [True] * 55555
prime[0] = False
prime[1] = False

for i in range(2, int(math.sqrt(len(prime))) + 1):
    if prime[i]:
        j = i * 2
        while j < len(prime):
            prime[j] = False
            j += i

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

for i in range(2, len(prime)):
    if prime[i] and i % 10 == 1:
        ans.append(str(i))
    if len(ans) >= n:
        break
print(' '.join(ans))

Solution (Python):
import math

n = int(input())
answers = []

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

start = 11
for i in range(n):
  for j in range(start, 55555, 5):
    if is_prime(j):
      answers += [str(j)]
      start = j + 5
      break

print(" ".join(answers))

Solution (Python):
N = 55555 + 1
prime_table  = [True] * N
d = {}
for i in range(2,N):
    if prime_table[i]:
        if i%5 not in d :
            d[i%5] = []
        d[i%5].append(i)
        j = 2
        while i * j < N:
            prime_table[i*j] = False
            j+=1

n = int(input())
print(" ".join([str(v) for v in d[1][:n]]))

Solution (Python):
N = int(input())
cur = 1
ans = []
while N > 0:
	to_test = int(str(cur) + "1")
	for j in range(2,int(to_test ** 0.5) + 1):
		if to_test % j == 0:
			break
	else:
		ans.append(str(to_test))
		N -= 1
	cur += 1
print(" ".join(ans))

Solution (Python):
m = 55555

p = [True] * m
for i in range(3, m):
    if not p[i]:
        continue
    for j in range(2, m):
        if j * i >= len(p):
            break
        p[i*j] = False

n = int(input())
if n <= 5:
    t = [2, 3, 5, 7, 11]
    print(" ".join([str(a) for a in t[:n]]))
else:
    ans = []
    for i in range(m):
        if len(ans) == n:
            break
        t = i*5+7
        if not p[t]:
            continue
        ans.append(t)
    print(" ".join([str(a) for a in ans]))

Solution (Python):
prime_five = []
for i in range(3, 55555):
	j = 2
	while j ** 2 <= i:
		if i % j == 0:
			break
		j += 1
	else:
		if i % 5 == 1:
			prime_five.append(i)

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

for i in range(n):
	ans.append(str(prime_five[i]))

print(' '.join(ans))

Solution (Python):
n = int(input())
ans=[]
def sosu(x):
    for i in range(2,x):
        if x % i ==0:
            return False
    return True

for i in range(11,55555,5):
    if sosu(i) and i % 5 ==1:
        ans.append(i)
        if len(ans) >= n:
            break

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

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

def isprime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for m in range(3, int(n**0.5) + 1, 2):
        if n % m == 0:
            return False
    return True

ans = [2]
p = 3
while len(ans) < N:
    p += 2
    if isprime(p) and p % 5 == 1:
        ans.append(p)
print(" ".join(map(str, ans)))

Solution (Python):
def is_prime(n):
    if n == 2:
        return True
    elif n%2 == 0:
        return False
    i = 3
    while n/i >= i:
        if n%i == 0:
            return False
        i += 2
    return True

primes = []
i = 2
while i < 55555:
    if is_prime(i):
        primes.append(i)
    i += 5

ans = []
n = int(input())
for i in range(n):
    ans.append(str(primes[i]))

print(' '.join(ans))

Solution (Python):
n = int(input())
m = 55555
prime = [True for i in range(m+1)]
prime[0] = prime[1] = False
for i in range(2, m+1):
    if prime[i] == True:
        for j in range(2, m+2):
            if i*j >= m+1:break;
            prime[i*j] = False
cnt = 0
ans = []
for i in range(2, m+1):
    if prime[i] == True and i%5 == 1:
        cnt += 1
        ans.append(i)
    if cnt == n:break
for i in range(n):
    print(ans[i], end = '')
    if i == n-1:print()
    else:print(" ", end = '')

Solution (Python):
Dlist = [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]

N = int(input())

for i in range(N):
    print(Dlist[i], end='')
    if i == N - 1:
        print()
    else:
        print(' ', end='')

Solution (Python):



import array


MAX_A = 55555


def sieve_of_eratosthenes(end, typecode="L"):
    """Enumerates the prime numbers below the given integer.

    :param int end: Prime numbers below this integer will be enumerated.
    :param str typecode: The type of the array to be returned (optional).
    :return: The array of the prime numbers.
    :rtype: :class:`array.array`
    """

    assert end > 1
    is_prime = array.array("B", (True for i in range(end)))
    is_prime[0] = False
    is_prime[1] = False
    primes = array.array(typecode)
    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


def solve(n):
    primes = sieve_of_eratosthenes(MAX_A + 1)
    return [prime for prime in primes if prime % 5 == 1][:n]


def main():
    print(*solve(int(input())))


if __name__ == '__main__':
    main()

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, 1451, 1471, 1481, 1511, 1531, 1571, 1601, 1621, 1721, 1741, 1801, 1811, 1831, 1861, 1871, 1901, 1931, 1951, 2011, 2081, 2111, 2131, 2141, 2161, 2221, 2251, 2281, 2311, 2341, 2351, 2371, 2381, 2411, 2441]
st=""
for i in range(N):
    st+=str(L[i])
    if i!=N-1:
        st+=" "
print(st)

Solution (Python):
n = int(input())
m = 55555
l = []
p = [True for i in range(m+1)]
p[0] = False
p[1] = False
ans = []
l = []
for i in range(2, m):
  if len(ans) >= n:
    break
  if p[i] == False:
    continue
  l.append(i)
  if i % 5 == 1:
    ans.append(i)
  j = i*2
  while j < m:
    p[j] = False
    j += i

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

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())
ans_list = []
for prime in primes(55555):
    if prime%10 == 1:
        ans_list.append(prime)
        N -= 1
        if N == 0:
            break
print(" ".join(list(map(str, ans_list))))

Solution (Python):
def main():
    """
    5 <= N <= 55
    ai is prime
    ai != aj
    sum(ai...ai5) is not prime
    """
    N = int(input())
    f(N)


def f(N):
    max_num = 55555
    e = eratosthenes(max_num * 5)
    ps = []
    for i in range(2, max_num+1):
        if e[i]:
            ps.append(i)
    
    

    
    ps2 = [p for p in ps if p % 5 == 1]
    print(*ps2[:N])


def TLE(N, e, ps):
    from itertools import combinations
    for c1 in combinations(ps, N):
        c2 = list(c1)
        ok = True
        c4 = None
        for c3 in combinations(c2, 5):
            c4 = list(c3)
            
            if not e[sum(c4)]:
                ok = False
                break
        if ok:
            print(*c4)
            return


def eratosthenes(N):
    is_prime = [True for _ in range(N + 1)]
    is_prime[0] = False
    is_prime[1] = False
    max_prime = int(N ** 0.5)
    for n in range(2, max_prime + 1):
        if is_prime[n]:
            for i in range(n * n, N + 1, n):
                is_prime[i] = False
    return is_prime


if __name__ == '__main__':
    main()

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






if __name__ == '__main__':
    n = int(input())
    x = [2]

    for i in range(2, 2000 + 1):
        if all(i % j != 0 for j in x):
            x.append(i)

    
    primes = [xi for xi in x if (xi % 5 == 1) and (xi >= 10)]
    print(' '.join(map(str, primes[:n])))

Solution (Python):
import numpy as np
n = input()
MAX_NUM = 55555
is_prime = [True] * MAX_NUM
is_prime[0] = False
is_prime[1] = False
primes = []
for num in range(MAX_NUM):
    if is_prime[num]:
        primes.append(num)
        for j in range(2*num, MAX_NUM, num):
            is_prime[j] = False
seq = filter(lambda x: x % 10 == 1, primes)
print " ".join(map(str, seq[:n]))

Solution (Python):

"""
D - Five, Five Everywhere
https://abc096.contest.atcoder.jp/tasks/abc096_d

"""
import sys
from sys import stdin
input = stdin.readline


def create_prime_list(limit):
    """ エラトステネスの篩でlimitまでの素数リストを求める
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    nums = [x for x in range(2, limit+1)]
    while nums[0] <= x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x % current_prime != 0]
    primes.extend(nums)
    return primes


def pick_numbers(N, primes):
    ans = []
    for p in primes:
        if p % 5 == 1:
            ans.append(p)
            if len(ans) == N:
                return ans
    return []


def main(args):
    primes = create_prime_list(55555)
    N = int(input())
    ans = pick_numbers(N, primes)
    print(*ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

        return True

    else:
        return False


n = int(input())

PRIME, idx = [0 for i in range(55)], 0
for i in range(2, 55556):
    if idx == 55:
        break

    if is_prime_five(i):
        PRIME[idx] = i
        idx += 1

ans_lst = PRIME[:n]
print(" ".join([str(i) for i in ans_lst]))

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

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

sol = []

for i in range(3, 55555+1, 10):
  if isprime(i):
    sol.append(i)
  if len(sol) >= n:
    break
print(*sol)

Solution (Python):
def isPrime(n):
    i = 2
    while i*i <= n:
        if n % i == 0:
            return False
        i += 1
    return True
 
l = []
i = 2
while i < 55556:
    if isPrime(i) and i%5 == 1:
        l.append(i)
    i += 1
 
N = int(input())
print(*l[:N])

Solution (Python):
from math import sqrt


def is_prime(x):
    if x == 2:
        return True

    if x < 2 or x % 2 == 0:
        return False

    for i in range(3, int(sqrt(x)) + 1, 2):
        if x % i == 0:
            return False

    return True


if __name__ == '__main__':
    N = int(input())
    prime_numbers = []
    for x in range(11, 55555 + 1, 10):
        if is_prime(x):
            prime_numbers.append(x)

        if len(prime_numbers) == N:
            break

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

Solution (Python):
import math
import itertools

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]

ans = primes(1400)[:N]

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

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]
n = int(input())
for i in range(n):
    print(P[i], end = " ")
print()

Solution (Python):
n = int(input())
a = (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(i,end = " ") for i in a[:n-1]]
print(a[n-1])

Solution (Python):
import numpy as np
n = int(input())
def prime():
    counter = 0
    primes = [2, 3]

    for n in range(5, 55555, 2):
        isprime = True
        for i in range(1, len(primes)):
            counter += 1
            if primes[i] ** 2 > n:
                break
            counter += 1
            if n % primes[i] == 0:
                isprime = False
                break
        if isprime:
            primes.append(n)
    return primes
primes_list = prime()
cnt = 0
res = []
for i in range(len(primes_list)):
    if primes_list[i] % 5 == 1:
        res.append(primes_list[i])
        cnt += 1
        if cnt == n:
            break
for i in range(n):
    print(res[i], end=' ')

Solution (Python):
n = int(input())
a = [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(i,end = " ") for i in a[:n-1]]
print(a[n-1])

Solution (Python):
def mkPrimeTbl(n):
    lst = [True] * (n + 1) 
    for i in range(2, int(n ** 0.5) + 1):
        if lst[i]:
            j = i
            while True:
                j += i
                if (j <= n):
                    lst[j] = False
                else:
                    break
    ret = []
    for i in range(2, n + 1):
        if lst[i]:
            ret += [i]

    return ret

if __name__ == '__main__':
    n = int(input())
    ptbl = mkPrimeTbl(55555)

    arr = []
    for x in ptbl:
        if (x % 10 == 1):
            arr += [x]
        if (len(arr) == n):
            break

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

Solution (Python):
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1


primeN = [2]
for i in range(2,10000):
    for j in range(len(primeN)):
        if i % primeN[j] == 0:
            break
        else:
            if j == len(primeN) - 1:
                primeN.append(i)
n=int(input())
ans=[]

for i  in primeN:
    if i%5==1:
      ans.append(i)
    if len(ans)==n:
        for x in ans:
            print(x,end=" ")
        exit()

Solution (Python):


N = int(input())


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

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

    return True

ans = []

n = 2


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

    n += 1

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

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

max_prime = 1382

primes = [True for i in range(max_prime+1)]

for i in range(2, max_prime):
    if primes[i]:
        for j in range(i+i, max_prime+1, i):
            primes[j] = False

primes[0] = False
primes[1] = False

primes_num = [i for i, el in enumerate(primes) if el]

ans = []

for p in primes_num:
    if p % 10 == 1:
        ans.append(p)

    if len(ans) == n:
        break


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

print()

Solution (Python):
import re
import math
import random
import itertools

def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):

        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False


if __name__ == '__main__':

    n = int(input())
    
    input_list = sieve_of_erastosthenes(55555)
    prime_list = [i for i, b in enumerate(input_list) if b == True]

    ans = list()
    for p in prime_list:
        if p % 5 == 1:
            ans.append(p)

    ans = ans[:n]

    for i in range(len(ans)-1):
        print("{} ".format(ans[i]), end='')
    print(ans[-1])

Solution (Python):
import itertools
import math
from sys import stdin


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]


def main():
    N = int(stdin.readline().rstrip())
    tmp = {x: [] for x in range(5)}
    for x in primes(1000000):
        tmp[x % 5].append(x)
        if len(tmp[x % 5]) == N:
            print(*tmp[x % 5])
            break


if __name__ == '__main__':
    main()

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

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


c = 0

for i in range(6, 55556, 5):
	if (is_prime(i)):
		c += 1
		if (c != N):
			print(i, end=' ')
		else:
			print(i)
			exit()

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, 1451]
n = int(input())
for i in range(n):
    print(P[i], end = " ")
print()

Solution (Python):
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
j = [341,561,645,1105,1387,1729,1905,2047,2465,2701,2821,3277]
lis = [x * 10 + 1 for x in range(1,5556)]
li = [x for x in lis if is_prime(x) and not x in j]
print(*li[:int(input())])

Solution (Python):
def d_five_five_everywhere(N):
    def prime_table(n):  
        is_prime = [True] * (n + 1)
        is_prime[0] = is_prime[1] = False  
        for j in range(2, int(n**0.5) + 1):
            if not is_prime[j]:
                continue
            for k in range(j * 2, n + 1, j):
                is_prime[k] = False  
        return [i for i in range(n + 1) if is_prime[i]]
    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))