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


def is_prime(n: int) -> bool:
    sq = int(sqrt(n))
    if sq * sq == n:
        return False

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


def primes(n: int) -> list:
    res = []

    if n < 2:
        return res
    res.append(2)

    if n < 3:
        return res
    res.append(3)

    for i in range(6, n+1, 6):
        if is_prime(i-1):
            res.append(i-1)

        if i + 1 > n:
            break

        if is_prime(i+1):
            res.append(i+1)

    return res


def five_five_everywhere(N: int) -> list:
    res = []
    count = 0
    for p in primes(55555):
        if p % 5 != 1:
            continue

        res.append(p)
        count += 1
        if count == N:
            return res

    return None


if __name__ == "__main__":
    N = int(input())
    ans = five_five_everywhere(N)
    print(' '.join(map(str, ans)))

Solution (Python):

import sys

def main():
	n = int(input())
	
	prime_numbers = []
	ans = []
	for num in range(3, 55556):
		if num == 3: prime_numbers.append(num)
		flg = True
		for prime_number in prime_numbers:
			if num % prime_number == 0:
				flg = False
				break
		
		if flg:
			prime_numbers.append(num)
			
	for val in prime_numbers:
		if val % 5 == 1:
			ans.append(val)
			if len(ans) >= n:
				break
				
	ans2 = ""
	for x in ans:
		ans2 = ans2 + str(x) + " "
			
	print(str.strip(ans2))
		
if __name__ == "__main__":
	main()

Solution (Python):
import numpy as np
N = int(input())


primes = np.arange(55556)
primes[:2] = 0
for i in range(2, int(55555 ** 0.5)):
    if primes[i]:
        primes[2 * i::i] = 0

for j in range(1, 5):
    ans = primes[j::5]
    ans = ans[ans > 0]
    if len(ans) >= N:
        ans = ans[:N]
        break

print(*ans)

Solution (Python):
def calc_primes(N):
    is_prime = {i: True for i in range(2, N+1)}
    primes = []
    for i in range(2, N+1):
        if is_prime[i]:
            primes.append(i)
            if i**2 <= N:
                for j in range(i**2, N+1, i):
                    is_prime[j] = False
    return primes


def main():
    N = int(input())
    arr = [str(x) for x in calc_primes(55555) if x % 5 == 1]
    print(" ".join(arr[:N]))


if __name__ == "__main__":
    main()

Solution (Python):
import sys

def makeprime():
  num = 2
  while num <= 55555:
    m = num - 1
    while m > 1 and num % m != 0:
      m -= 1
    if m == 1:
      yield num
      num += 1
    else:
      num += 1 


def main():
  input = sys.stdin.readline
  N = int(input())
  A = []
  for p in makeprime():
    if p % 5 == 1:
      A.append(str(p))
    if len(A) == N:
      break

  print(" ".join(A))


if __name__ == '__main__':
  main()

Solution (Python):
import sys
from itertools import count

def makeprime():
  num = 2
  while num <= 55555:
    m = num - 1
    while m > 1 and num % m != 0:
      m -= 1
    if m == 1:
      yield num
      num += 1
    else:
      num += 1 


def main():
  input = sys.stdin.readline
  N = int(input())
  p = makeprime()
  A = []
  while len(A) < N:
    np = next(p)
    if np % 5 == 1:
      A.append(np)
  for n in A:
    print(n, end=' ')


if __name__ == '__main__':
  main()

Solution (Python):
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]
c=""
for i in range(int(input())):
    c+=str(d[i])+" "
print(c)

Solution (Python):
n = int(input())
primes = []
isprime = [0] * 2 + [1] * 60000
for i in range(2,60000):
    if isprime[i] == 1:
        primes.append(i)
        for j in range(2,60000//i):
            isprime[i*j] = 0
prime2 = []
for p in primes:
    if len(prime2) > 60:
        break
    if p % 5 == 2:
        prime2.append(p)
for i in range(n):
    print(prime2[i], end = ' ')
print()

Solution (Python):
from collections import defaultdict

max_ = 55555
primes = defaultdict(list)
is_prime = [True]*(max_+1)

for i in range(2,max_+1):
    if is_prime[i]:
        primes[i%5].append(i)
        for j in range(max_//i+1):
            is_prime[j*i] = False



n = int(input())
print(" ".join(map(str, primes[1][:n])))

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

Solution (Python):
is_prime = [True]*55556
ass = []
is_prime[0] = False
is_prime[1] = False
for i in range(2,int(55555**0.5)+1):
  if not is_prime:
    continue
  else:
    if is_prime:
      for j in range(2*i,55556,i):
        is_prime[j] = False
for k in range(55556):
  if is_prime[k]:
    ass.append(k)
L = []
for l in range(len(ass)):
  if ass[l]%5 == 1:
    L.append(ass[l])
N = int(input())
for i in range(N):
  print(L[i],end = ' ')

Solution (Python):

n = int(input()) 
ans_list = [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, ans_list[:n])))

Solution (Python):
def primes(max_number):
    pr = list(range(3, max_number+1, 2))
    lpr = len(pr)
    for i,n in enumerate(pr):
        if n:
            if n*n > max_number:
                break
            for j in range(i+n, lpr, n):
                pr[j] = 0
    yield 2
    yield from[i for i in pr if i]

p = list(primes(55555))
n = int(input())
cnt = 0
i = 0
ans = []
while cnt < n:
    if p[i] % 5 == 1:
        ans.append(p[i])
        cnt += 1
    i += 1
print(*ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def primes(N, n):
    L = [v for v in range(3, N+1)]
    while L:
        p = L.pop(0)
        if p % 10 == n:
            yield p
        L = list(filter(lambda x: x % p != 0, L))


N = int(input())
cnt = 0
ans = []
for p in primes(3000, 1):
    ans.append(p)
    cnt += 1
    if cnt == N:
        print(" ".join(map(str, ans)))
        break

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def primes(N, n):
    L = [v for v in range(3, N+1)]
    primes = []
    while L:
        p = L.pop(0)
        if p % 10 == n:
            primes.append(p)
        L = list(filter(lambda x: x % p != 0, L))
    return primes


N = int(input())
ans = primes(3000, 1)[:N]
print(" ".join(map(str, ans)))

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

def check(n):
    sup = m.floor(pow(n,1/2))
    for i in range(2,sup+1):
        if n % i == 0:
            return False
    return True

for i in range(2,11112,2):
    if len(prime) == N:
        break
    p = 5*i + 1
    
    if check(p) is True:
        prime.append(p)

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


def debug():
    import itertools
    for e in itertools.combinations(prime,5):
        
        if check(sum(e)) is True:
            print("No")
            return
    print("Yes")

Solution (Python):
MAX=55555

from collections import defaultdict
f = defaultdict(int)

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

p=2
while p<=MAX:
    m=2*p
    while m<=MAX:
        f[m]=1
        m+=p
    p+=1
    while f[p]!=0:
        p+=1
        if p>MAX:
            break
    if p%5==1:
        ans.append(p)
        if len(ans)==N:
            break
print(' '.join([str(a) for a in ans]))

Solution (Python):
import math

def sieve_of_eratosthenes(n):
    prime=[]
    limit=math.sqrt(n)
    data=[i+1 for i in range(1,n)]
    while True:
        p=data[0]
        if limit<p:
            return prime+data
        prime.append(p)
        data=[e for e in data if e%p!=0]

n=55555
primes=sieve_of_eratosthenes(n)
k=(len(primes))
A=[]
for i in range(k):
    if primes[i]%5==1:
        A.append(primes[i])
N=int(input())
print(' '.join(map(str,A[:N])))