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

def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    pt = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)

    for p in P:
        if p%5 ==1:
            pt.append(p)
     
    return pt

limit = 55555
P = eratosthenes(limit)

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

Solution (Python):


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def primes(N):
    is_prime = [True]*(N+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, N+1):
        if is_prime[i]:
            for j in range(2*i, N+1, i):
                is_prime[j] = False
    return [i for i, p in enumerate(is_prime) if p and i%5 == 1]


def solve():
    N = read_int()
    some_primes = primes(2000)
    print(*some_primes[:N])


if __name__ == '__main__':
    solve()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    isprime = [True if i % 2 else False for i in range(55555+1)]
    isprime[1] = False
    rem = 1
    ans = []
    for i, j in enumerate(isprime[2:], start=2):
        if not j:
            continue
        ind = i * 2
        while ind <= 55555:
            isprime[ind] = False
            ind += i

    for i, j in enumerate(isprime):
        if not j:
            continue
        if i % 5 == rem:
            ans.append(i)
    
    print(*ans[:int(input())])

if __name__ == '__main__':
    main()

Solution (Python):
import math

def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False
  
  m = math.floor(math.sqrt(n)) + 1
  for p in range(3, m, 2):
    if n % p == 0:
      return False
  return True

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

for i in range(2,55556):
  if isPrime(i) and i%5 == 1:
    ans.append(i)
  if len(ans) == N:
    break

print(*ans)

Solution (Python):
import sys
import math
import collections
import bisect
import itertools



sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))




def main():
    
    def make_prime_nums(n):
        prime_nums = [2 if n >= 2 else None]
        for i in range(3, n + 1):
            for p in prime_nums:
                if p >= int(i ** (1 / 2)) + 1:
                    prime_nums.append(i)
                    break
                if i % p == 0:
                    break
        return prime_nums

    n = ni()
    p = make_prime_nums(2000)

    ans = []
    for pi in p:
        if pi % 10 == 1:
            ans.append(pi)
        if len(ans) == n:
            break

    print(*ans, sep=" ")



if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [1] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            p[2 * i * (i + 1) :: 2 * i + 1] = [0] * (((m - 1) - 2 * i * (i + 1)) // (2 * i + 1) + 1)

    a = [2 * i + 1 for i in range(m) if p[i]]
    a[0] = 2
    return a


def main():
    N = int(readline())

    P = prime_numbers(55555)

    A = []
    for p in P:
        if p % 5 == 1:
            A.append(p)
            if len(A) == N:
                break

    print(' '.join(map(str, A)))
    return


if __name__ == '__main__':
    main()

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

U = 55556
is_prime = np.full(U+1, True)
is_prime[:2] = False
for p in range(2, U+1):
    if p*p > U:
        break
    if is_prime[p]:
        is_prime[p*p::p] = False


ans = []
i = 2
while len(ans) < N and i < 55556:
    if i % 5 == 1 and is_prime[i] == True:
        ans.append(i)
    i += 1
print(*ans)

Solution (Python):
def eratosthenes(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0], is_prime[1] = False, False
    prime = []
    for i in range(2, n+1):
        if is_prime[i]:
            prime.append(i)
            for j in range(2*i, n+1, i):
                is_prime[j] = False
    return prime


N = int(input())

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

Solution (Python):
N=int(input())
B=[1]*55556

B[0]=0
B[1]=0
for i in range(2,55556):
    if B[i]==0:continue
    temp=i
    cnt=2
    while temp*cnt<=55555:
        B[temp*cnt]=0
        cnt+=1
PN=[]
for i in range(2,55556):
    if B[i]:
        PN.append(i)

for i in range(1,10,2):
    cnt=1
    ans=[2]
    for p in PN:
        if p%10==i:
            ans.append(p)
            cnt+=1
            if cnt==N:
                print(*ans)
                exit()

Solution (Python):
n=int(input())
def prime(INF=10**6+1):
  p=[1]*INF
  for i in range(2,INF):
    if p[i]:
      for j in range(2*i,INF,i):p[j]=0
  p[0],p[1]=0,0
  return p
p=prime()
a=[]
cnt=0
for i in range(10**6+1):
  if p[i] and i%5==1:
    a+=[i]
    cnt+=1
  if cnt==n:break
print(*a)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

lim = 55555
prime = [1]*(lim+1)
prime[0] = 0
prime[1] = 0

for i in range(lim+1):
	if prime[i] == 1:
		for j in range(2, lim//i + 1):
			prime[i*j] = 0

p = [i for i in range(lim+1) if prime[i]]

ans = [x for x in p if x%5 == 2]
print(*ans[:N])

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7


lim = 55555
prime = [1]*(lim+1)
prime[0] = 0
prime[1] = 0

for i in range(lim+1):
	if prime[i] == 1:
		for j in range(2, lim//i + 1):
			prime[i*j] = 0

p = []
i = 0
while i <= lim:
	if prime[i] and i%10 == 1:
		p.append(i)
	i += 1

N = INT()
print(*p[:N])

Solution (Python):
def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


N = int(input())

result = []
prime_table = make_prime_table(55555)
for i in range(3, 55555 + 1, 2):
    if prime_table[i] == i and i % 5 == 1:
        result.append(i)
    if len(result) == N:
        break
print(*result)

Solution (Python):
import sys

input = sys.stdin.readline


def calc_prime_numbers(n):
    """Sieve of Eratosthenes"""
    if n == 1:
        return []

    is_prime = [True] * (n + 1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        for j in range(2 * i, n + 1, i):
            is_prime[j] = False

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

    return prime_number_list


def main():
    N = int(input())

    MAX_A = 55555
    prime_numbers = calc_prime_numbers(MAX_A)

    ans = []
    for prime_number in prime_numbers:
        if prime_number % 5 == 1:
            ans.append(prime_number)

        if len(ans) == N:
            break

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


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
l = [0]*(55556)
i = 2
while i <= 55555:
    j = 2
    while i*j <= 55555:
        l[i*j] = 1
        j += 1
    i += 1
ans = []
for i in range(3,55556):
    if l[i]:
        continue
    if ((i-1)//2)%5 == 0:
        ans.append(i)
print(*ans[:n])

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

def get_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
    for i, b in enumerate(is_prime):
        if b:
            yield i

primes_and_mod1 = []
for i in get_primes(55999):
    if i % 5 == 1:
        primes_and_mod1.append(i)

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

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(*ans[:N])

Solution (Python):
import math
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

def get_prime(n): 
    X = [i for i in range(2,n+1)] 
    prime = []
    mx = math.sqrt(n) + 1 

    while True:
        p = min(X) 
        if mx <= p:
            prime.extend(X) 
            break
        prime.append(p) 
        X = [i for i in X if i % p != 0]

    return prime




INF=10**20
def main():
    N = ii()
    P = set(get_prime(55555))

    ans = [2]
    p = 2
    while len(ans) < N:
        p += 5
        while p < 55555 and not p in P:
            p += 5
        
        ans.append(p)
    
    
    print(*ans,sep=' ')
        






if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
d=[]
for i in range(1,11111+1):
  m=5*i-1
  if m%2==0:
    continue
  f=3
  while f*f<m+1:
    if m%f==0 or len(d)==n:
      break
    f+=2
  else:
    d.append(m)
print(*d)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7



def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(pow(n, 0.5)) + 1):
        if n % k == 0:
            return False
    return True


def resolve():
    n = int(input())
    primes = []
    for i in range(1, 55556):
        if i % 5 == 1 and is_prime(i):
            primes.append(i)
            if len(primes) == n:
                break
    print(*primes)


if __name__ == '__main__':
    resolve()

Solution (Python):

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError("n is int type.")
    if n < 2:
        raise ValueError("n is more than 2")
    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]








N = int(input())
P = get_sieve_of_eratosthenes(55555)
cnt = 0
for p in P:
    if p % 5 == 1:
        print(p)
        cnt += 1
    if cnt == N:
        break

Solution (Python):

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError("n is int type.")
    if n < 2:
        raise ValueError("n is more than 2")
    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]








N = int(input())
P = get_sieve_of_eratosthenes(55555)
cnt = 0
for p in P:
    if p % 5 == 1:
        print(p)
        cnt += 1
    if cnt == N:
        break

Solution (Python):
N=int(input())
ans=[]
n = 55555
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

for i in primes:
    if (i%5)==1:
        ans.append(i)

print(*ans[:N])

Solution (Python):
def get_primes(n):
  if n<=1:
    return []
  prime=[2]
  limit=int(n**0.5)
  p=[i+1 for i in range(2,n,2)]
  while limit>p[0]:
    prime.append(p[0])
    p=[j for j in p if j%p[0]!=0]
  return prime+p

N = int(input())

ans = []
primes = get_primes(55555)
for i in range(3, 55555 + 1, 2):
  if i in primes and i%5 == 1:
    ans.append(i)
  if len(ans) == N:
    break
print(*ans)

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
  else:
    return True
    

for i in range(2,55556):
  if prime(i) and i%5==1:
    l.append(i)
for i in range(n):
  print(l[i],end=" ")

Solution (Python):
n,P,A=int(input()),[2],[]
for L in range(3,9999):
 if len(A)==n:break
 if all(L%M for M in P):
  P+=L,
  if L%5>3:A+=L,
print(*A)

Solution (Python):
n,P,A=int(input()),[2],[]
for L in range(3,9999):
 if len(A)==n:break
 if all(L%M for M in P):
  P+=L,
  if L%5==1:A+=L,
print(*A)

Solution (Python):
n,P,A=int(input()),[2],[]
for L in range(3,55556,2):
 if len(A)==n:break
 if all(L%M for M in P):
  P+=L,
  if L%5==1:A+=L,
print(*A)

Solution (Python):
n = int(input())
P, A = [2], []
for L in range(3, 55556, 2):
  if len(A) == n:
    break
  if all(L % M for M in P):
    P += L,
    if L % 5 == 1:
      A += L,
print(*A)

Solution (Python):
N = int(input())
prime = [True] * 55556
prime[0] = False
prime[1] = False
for i in range(4,55556,2):
    prime[i] = False
for i in range(3,55556,2):
    if prime[i] == True:
        for j in range(i*2,55556,i):
            prime[j] = False
lis = []
for i in range(55556):
    if prime[i] == True and i % 5 == 1:
        lis.append(i)
    if len(lis) == N:
        break

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

Solution (Python):
N = int(input())
prime = [True] * 55556
prime[0] = False
prime[1] = False
for i in range(4,55556,2):
    prime[i] = False
for i in range(3,55556):
    if prime[i] == True:
        for j in range(i*2,55556,i):
            prime[j] = False
lis = []
for i in range(55556):
    if prime[i] == True and i % 5 == 1:
        lis.append(i)
    if len(lis) == N:
        break

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

Solution (Python):
n=int(input())
sosuu=[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,2521,2531,2551,2591,2621,2671,2711,2731,2741,2791,2801,2851,2861,2971,3001,3011,3041,3061,3121,3181,3191,3221,3251,3271,3301,3331,3361,3371,3391,3461,3491,3511,3541,3571,3581,3631,3671,3691,3701,3761,3821,3851,3881,3911,3931,4001,4021,4051,4091,4111,4201,4211,4231,4241,4261,4271,4391,4421,4441,4451,4481,4561,4591,4621,4651,4691,4721,4751,4801,4831,4861,4871,4931,4951,5011,5021,5051,5081,5101,5171,5231,5261,5281,5351,5381,5431,5441,5471,5501,5521,5531,5581,5591,5641,5651,5701,5711,5741,5791,5801,5821,5851,5861,5881,5981,6011,6091,6101,6121,6131,6151,6211,6221,6271,6301,6311,6361,6421,6451,6481,6491,6521,6551,6571,6581,6661,6691,6701,6761,6781,6791,6841,6871,6911,6961,6971,6991,7001,7121,7151,7211,7321,7331,7351,7411,7451,7481,7541,7561,7591]
print(*sosuu[:n])

Solution (Python):



def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError("n is int-type.")
    if n < 2:
        raise ValueError("n is more than 2")
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

N = int(input())
primes = get_sieve_of_eratosthenes(5000)
ans=[]

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

print(" ".join(list(map(str,ans))))

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

num = [1]*55556

for i in range(2,55556):
    if num[i]==1:
        k=2
        while i*k<=55555:
            num[i*k]=0
            k+=1

ans = []

l=2
for i in range(n):
    for j in range(l,11111):
        if num[j*5+1]==1:
            ans.append(str(j*5+1))
            l=j+1
            break
print(' '.join(ans))

Solution (Python):
n = int(input())
a = 11
p = [11]

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

while len(p) < n:
    a += 5
    if is_prime(a):
        p.append(a)

print(*p)

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

x = primes(1500)
res= [2]

for i in x:
    if i % 5 ==4:
        res.append(i)
y =res[:n]
yyy = list(map(lambda x: str(x),y))
yy =" ".join(yyy)
print(yy)

Solution (Python):
n = int(input())
count = 0
preemos = []

is_prime = [True] * 55555
is_prime[0],is_prime[1] = False, False

for i in range(2, 55555):
  if count == n: break
  if is_prime[i]:
    if i % 10 == 1:
      count += 1
      preemos.append(i)
    for j in range(i, 55555, i):
      is_prime[j] = False
      
for i in preemos:
  print(i, end = " ")

Solution (Python):
from math import sqrt
def sieve(n):
    if n <= 4:
        return list(range(2, n))
    def _sieve_of_eratosthenes(n):
        limit = int(sqrt(n))+1
        table = [1] * n
        table[0] = table[1] = 0
        for i in range(2, limit):
            if table[i]:
                for j in range(i**2, n, i):
                    table[j] = 0
        return [i for i in range(2, n) if table[i]]
    return _sieve_of_eratosthenes(n)
print(*[x for x in sieve(5555) if x % 5 == 1][:int(input())])

Solution (Python):
from math import sqrt
def sieve(n):
    if n <= 4:
        return list(range(2, n))
    def _sieve_of_eratosthenes(n):
        limit = int(sqrt(n))+1
        table = [1] * n
        table[0] = table[1] = 0
        for i in range(2, limit):
            if table[i]:
                for j in range(i**2, n, i):
                    table[j] = 0
        return [i for i in range(2, n) if table[i]]
    return _sieve_of_eratosthenes(n)
print(*[x for x in sieve(55555) if x % 10 == 7][:int(input())])

Solution (Python):

import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right, bisect_left
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7


def cal_primes(N):
    
    candidate = [*range(2, N+1)]
    primes = []

    while candidate[0]**2 <= N:
        primes.append(candidate[0])
        candidate = [*filter(lambda x: x % candidate[0] != 0, candidate)]
    
    primes.extend(candidate)
    return primes

def main():
    N = int(input())
    primes = cal_primes(55555)
    primes = [*filter(lambda x: x % 5 == 1, primes)]
    
    print(*primes[: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 = [v for v in p if v % 5 == 1]
print(*ans[:n])

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

memo = [1] * N
memo[0] = 0
memo[1] = 0

for i in range(2, N):
    if memo[i]:
        for j in range(2, N):
            if i * j >= N:
                break
            memo[i*j] = 0

ans = []
for i in range(2, N):
    if memo[i]:
        if i % 5 == 1:
            ans.append(str(i))

print(' '.join(ans[:n]))

Solution (Python):
def prime(n):
    if n > 1:  
        for i in range(2, n): 
            if (n % i) == 0: 
                return False
                break
        else: 
            return True 
    else: 
        return False
n = int(input())
c = 1
ans = []
for i in range(n):
  flag = True
  while flag:
    val = prime((c*5)+1)
    if val:
      ans.append((c*5)+1)
      flag = False
    c+=1
print(*ans)

Solution (Python):
N = int(input())
L = [0,0] + [1]*55555
K = []
for i in range (len(L)):
  if L[i]:
    for j in range (2*i,len(L),i):
      L[j] = 0
    if i%5 == 1:
      K.append(i)
      if len(K) == N:
          break
print(*K)

Solution (Python):
N=int(input())
lineup=[7,17,37,47,107,127,137,157,167,197,227,257,277,307,317,337,347,367,397,467,487,557,577,587,607,617,677,727,757,797,827,857,877,887,907,947,967,977,997,1087,1097,1117,1187,1217,1237,1277,1297,1307,1327,1367,1427,1447,1487,1567,1597,1607]
print(*lineup[:N])

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
s = set()
prime = []
for i in range(2, 55556):
    if i in s:
        continue
    if i%5==1:
        prime.append(i)
    cnt = 1
    while i*cnt<=55555:
        s.add(i*cnt)
        cnt += 1

print(*prime[:N])

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

N = int(readline())

fact = [True] * 55556
fact[0] = False
fact[1] = False
ans = []
for i in range(len(fact)):
  if fact[i]:
    for j in range(i * 2, len(fact), i):
      fact[j] = False
    if i % 5 == 1:
      ans.append(i)
      if len(ans) == N:
        break
      
print(*ans)

Solution (Python):
import sys

N = int(sys.stdin.readline().rstrip())


import math

def sieve_of_eratosthenes(n):
    prime_list = []  
    A = [1]*(n+1)    
    A[0] = A[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if A[i]:
            prime_list.append(i)
            for j in range(i**2,n+1,i):
                A[j] = 0
    for i in range(math.floor(math.sqrt(n))+1,n+1):
        if A[i] == 1:
            prime_list.append(i)
    return prime_list


prime_list = sieve_of_eratosthenes(1361)

ANS = [2]
for p in prime_list:
    if p == 2:
        continue
    else:
        if p % 10 == 1:
            ANS.append(p)
            if len(ANS) == N:
                break

print(*ANS)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()

ANS = [2,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]
print(*ANS[:N])

Solution (Python):
import sys

N = int(sys.stdin.readline().rstrip())

ANS = [2,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]
print(*ANS[:N])

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()


import math

def sieve_of_eratosthenes(n):
    prime_list = []  
    A = [1]*(n+1)    
    A[0] = A[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if A[i]:
            prime_list.append(i)
            for j in range(i**2,n+1,i):
                A[j] = 0
    for i in range(math.floor(math.sqrt(n))+1,n+1):
        if A[i] == 1:
            prime_list.append(i)
    return prime_list


prime_list = sieve_of_eratosthenes(55555)

ANS = [2]
for p in prime_list:
    if p == 2:
        continue
    else:
        if p % 10 == 1:
            ANS.append(p)
            if len(ANS) == N:
                break

print(*ANS)

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

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 = [v for v in p if v % 5 == 1]
print(*ans[:n])

Solution (Python):

def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, int(n ** 0.5) + 1):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


N = int(input())

result = []
prime_table = make_prime_table(55555)
for i in range(3, 55555 + 1, 2):
    if prime_table[i] == i and i % 5 == 1:
        result.append(i)
    if len(result) == N:
        break
print(*result)

Solution (Python):

def make_prime_table(N):
    sieve = [0] * (N + 1)
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, N + 1):
        if sieve[i] != 0:
            continue
        sieve[i] = i
        for j in range(i * i, N + 1, i):
            if sieve[j] == 0:
                sieve[j] = i
    return sieve

N = int(input())

result = []
prime_table = make_prime_table(55555)
for i in range(3, 55555 + 1, 2):
    if prime_table[i] == i and i % 5 == 1:
        result.append(i)
    if len(result) == N:
        break
print(*result)

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

mp = [1]*(r+1)
i = 2

while 2*i <= r:
  j = 2
  while i*j <= r:
    mp[i*j] = 0
    j += 1
  i += 1
  
k = 0
l = 1
rlt = []
while k < N:
  if mp[30*l-1] == 1:
    rlt.append(30*l-1)
    k += 1
  l += 1

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

Solution (Python):

def primes(n):
    m = 1297
    is_prime = [True] * (m + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(m**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, m + 1, i):
            is_prime[j] = False
    return [i for i in range(m + 1)
            if is_prime[i] and i % 5 == 2][:n]


print(*primes(int(input())))

Solution (Python):

def primes(n):
    m = 1297
    is_prime = [True] * (m + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(m**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, m + 1, i):
            is_prime[j] = False
    return [i for i in range(m + 1)
            if is_prime[i] and i % 5 == 2][:n]


print(*primes(int(input())))

Solution (Python):

def primes(n):
    m = 1303
    is_prime = [True] * (m + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(m**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, m + 1, i):
            is_prime[j] = False
    return [i for i in range(m + 1)
            if is_prime[i] and str(i).endswith("3")][:n]


print(*primes(int(input())))

Solution (Python):

def primes(n):
    m = 1303
    is_prime = [True] * (m + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(m**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, m + 1, i):
            is_prime[j] = False
    return [i for i in range(m + 1)
            if is_prime[i] and str(i).endswith("3")][:n]


print(*primes(int(input())))

Solution (Python):

def primes(n):
    m = 10000
    is_prime = [True] * (m + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(m**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, m + 1, i):
            is_prime[j] = False
    return [i for i in range(m + 1)
            if is_prime[i] and str(i).endswith("3")][:n]


print(*primes(int(input())))

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

def get_sieve_of_atkin(n):  
    is_prime = {i: False for i in range(5, n + 1)}
    limit = int(n**0.5) + 1
    for x in range(1, limit):
        for y in range(1, limit):
            k = 4 * x**2 + y**2
            if k <= n and (k % 12 == 1 or k % 12 == 5):
                is_prime[k] = not is_prime[k]
            k = 3 * x**2 + y**2
            if k <= n and k % 12 == 7:
                is_prime[k] = not is_prime[k]
            k = 3 * x**2 - y**2
            if x > y and k <= n and k % 12 == 11:
                is_prime[k] = not is_prime[k]
    for k in range(5, limit):
        if is_prime[k]:
            i = 1
            while i * k**2 <= n:
                is_prime[i * k**2] = False
                i += 1
    return [2, 3] + [i for i in range(5, n + 1, 2) if is_prime[i]]

sieve = get_sieve_of_atkin(55555)
ANS = []

for prime in sieve:
    if prime % 5 == 1:
        ANS.append(prime)

print(*ANS[:n])