Problem:


Score : 600 points

Problem Statement

Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers.  

She thinks that a set S = \{a_{1}, a_{2}, ..., a_{N}\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is not 1.

Nagase wants to find a special set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a special set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.

Constraints

3 \leq N \leq 20000

Input

Input is given from Standard Input in the following format:

N

Output

Output N space-separated integers, denoting the elements of the set S. S must satisfy the following conditions :

The elements must be distinct positive integers not exceeding 30000.

The gcd of all elements of S is 1, i.e. there does not exist an integer d > 1 that divides all elements of S.

S is a special set.

If there are multiple solutions, you may output any of them. The elements of S may be printed in any order. It is guaranteed that at least one solution exist under the given contraints.

Sample Input 1

3

Sample Output 1

2 5 63

\{2, 5, 63\} is special because gcd(2, 5 + 63) = 2, gcd(5, 2 + 63) = 5, gcd(63, 2 + 5) = 7. Also, gcd(2, 5, 63) = 1. Thus, this set satisfies all the criteria.

Note that \{2, 4, 6\} is not a valid solution because gcd(2, 4, 6) = 2 > 1.

Sample Input 2

4

Sample Output 2

2 5 20 63

\{2, 5, 20, 63\} is special because gcd(2, 5 + 20 + 63) = 2, gcd(5, 2 + 20 + 63) = 5, gcd(20, 2 + 5 + 63) = 10, gcd(63, 2 + 5 + 20) = 9. Also, gcd(2, 5, 20, 63) = 1. Thus, this set satisfies all the criteria.



Sample input:
3


Sample output:
2 5 63

Submission status: Accepted

Solution code:
N = int(input())

if N == 3:
	print(2, 5, 63)
elif N == 4:
	print(2, 5, 20, 63)
else:
	n = N // 8
	ans = []
	for i in range(n):
		ans.append(12 * i + 2)
		ans.append(12 * i + 3)
		ans.append(12 * i + 4)
		ans.append(12 * i + 6)
		ans.append(12 * i + 8)
		ans.append(12 * i + 9)
		ans.append(12 * i + 10)
		ans.append(12 * i + 12)
	j =  N % 8
	if j == 1:
		ans.append(12 * n + 6)
	elif j == 2:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
	elif j == 3:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
		ans.append(12 * n + 12)
	elif j == 4:
		ans.append(12 * n + 3)
		ans.append(12 * n + 9)
		ans.append(12 * n + 6)
		ans.append(12 * n + 12)
	elif j == 5:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 6)
		ans.append(12 * n + 9)
	elif j == 6:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 8)
		ans.append(12 * n + 9)
		ans.append(12 * n + 10)
	elif j == 7:
		ans.append(12 * n + 2)
		ans.append(12 * n + 3)
		ans.append(12 * n + 4)
		ans.append(12 * n + 6)
		ans.append(12 * n + 8)
		ans.append(12 * n + 9)
		ans.append(12 * n + 10)
	ans = list(map(str, ans))
	print(" ".join(ans))

Submission status: Accepted

Solution code:
N = int(input())

if N == 3:
    print('2 5 63')
else:
    A2 = [a for a in range(2, 30001, 2) if a % 6 != 0]
    A3 = [a for a in range(3, 30001, 6)]
    A6 = [a for a in range(6, 30001, 6)]

    a2 = min(10000, (N - 2) // 2 * 2)
    N -= a2
    a3 = min(5000, N // 2 * 2)
    a6 = N - a3

    ans = A2[: a2] + A3[: a3] + A6[: a6]
    print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
if n==3:
    print(2,5,63)
elif n==4:
    print(2,5,20,63)
elif n==5:
    print(2,5,20,63,1260)
else:
    ans = []
    if n<1000:
        ans = [2,3,4,8,9,10]
        for i in range(n-6):
            ans.append(6*(i+1))
    else:
        m=-(-n//8)
        a = []
        for i in range(1, 12*m+1):
            if i % 2 == 0 or i % 3 == 0:
                a.append(i)
        b = 8*m-n
        for x in a:
            if x%6==0 and b>0:
                b-=1
            else:
                ans.append(x)
    print(' '.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())
P2 = [[0, 0, 0] for _ in range(5000)]
P3 = [[0, 0] for _ in range(2500)]
limit = 30000
for i in range(5000):
  P2[i] = [6 * (i + 1) - 2, 6 * (i + 1), 6 * (i + 1) + 2]
P2[-1][-1] = 2
for i in range(2500):
  P3[i] = [12 * i + 3, 12 * i + 9]
if N == 3:
  print(2,3,25)
elif N == 4:
  print(2,3,4,9)
elif N == 6:
  print(2,3,4,6,9,12)
else:
  def SP(N):
    if N == 19999:
      P = P2 + P3
      P[0] = [4, 8]
      return P
    _k = -(-max(N - 12500, 0) // 3)
    N -= 3 * _k
    k = N // 5
    m = N % 5
    if m == 0:
      P = P2[:k + _k] + P3[:k]
    elif m == 1:
      P = P2[:k + 1 + _k] + P3[:k - 1]
    elif m == 2:
      P = P2[:k + _k] + P3[:k + 1]
    elif m == 3:
      P = P2[:k + 1 + _k] + P3[:k]
    elif k >= 2499:
      P = P2[:k + 2 + _k] + P3[:k - 1]
    else:
      P = P2[:k + _k] + P3[:k + 2]
    return P
  P = SP(N)
  print(' '.join([' '.join([str(_p) for _p in p]) for p in P]))

Submission status: Accepted

Solution code:
N = int(input())

if N == 3:
    print(2, 5, 63)
    exit()

two = []
three = []
six = []
for i in range(0, 30000, 12):
    two.append((i + 2, i + 4))
    two.append((i + 8, i + 10))
    three.append((i + 3, i + 9))
    six.append(i + 6)
    six.append(i + 12)

if N <= 10002:
    two_num = N - 2
    three_num = 2
    six_num = 0
elif N <= 15000:
    two_num = 10000
    three_num = N - 10000
    six_num = 0
else:
    two_num = 10000
    three_num = 5000
    six_num = N - 15000
if two_num % 2 == 1:
    two_num -= 1
    six_num += 1
if three_num % 2 == 1:
    three_num -= 1
    six_num += 1

ans = []
for i in range(two_num // 2):
    a, b = two[i]
    ans.append(a)
    ans.append(b)
for i in range(three_num // 2):
    a, b = three[i]
    ans.append(a)
    ans.append(b)
for i in range(six_num):
    ans.append(six[i])

print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
m=0
m+=n
co=0
ju=True
li=[]
while n>3:
    li.clear()
    while len(li)<2:
        co+=1
        if co*2%3:
            if co*2>30000:
                ju=False
                break
            else:
                li.append(co*2)
    if ju and n>2:
        for i in li:
            ans.append(i)
        n-=2
    else:
        break
ju=True
co=0
while n>1:
    li.clear()
    while len(li)<2:
        co+=1
        if co*3%2:
            if co*3>30000:
                ju=False
                break
            else:
                li.append(co*3)
    if ju:
        ans.append(li[0])
        ans.append(li[1])
        n-=2
    else:
        break
co=1
while n>0:
    ans.append(co*6)
    co+=1
    n-=1
if m==3:
    ans=[2,5,63]
elif m==4:
    ans=[2,5,50,63]
for i in range(m):
    if i==n-1:
        print(ans[i])
    else:
        print(ans[i],end=' ')

Submission status: Accepted

Solution code:
n = int(input())

div, mod = divmod(n, 4)
ans = []

if n == 3:
    print(2, 5, 63)
    exit()
if n == 4:
    print(2, 5, 20, 63)
    exit()
if n == 5:
    print(2, 5, 20, 30, 63)
    exit()
    
cnt = 0
i = 0
for i in range(div):
    cnt += 15
    ans.append(6*i + 2)
    ans.append(6*i + 3)
    ans.append(6*i + 4)
    ans.append(6*i + 6)
if mod == 1:
    i += 1
    cnt += 2
    ans.append(6*i + 2)
if mod == 2:
    i += 1
    cnt += 5
    ans.append(6*i + 2)
    ans.append(6*i + 3)
if mod == 3:
    i += 1
    cnt += 9
    ans.append(6*i + 2)
    ans.append(6*i + 3)
    ans.append(6*i + 4)

if cnt % 6 == 0:
    pass
if cnt % 6 == 2:
    ans = ans[0:4] + ans[5:] + [ans[-1] - ans[-1] % 6 + 6]
if cnt % 6 == 3:
    ans = ans[0:5] + ans[6:] + [ans[-1] - ans[-1] % 6 + 6]
if cnt % 6 == 5:
    ans = ans[0:5] + ans[6:] + [6 * (ans[-1] // 6) + 4]
print(*ans)

Submission status: Accepted

Solution code:
n = int(input())

if n == 3:
    print(2, 5, 63)
    exit()

n -= 4
a, b = 2, 2

k = min(n // 3, 4999)
a += k * 3
n -= k * 3

if n % 2 == 1:
    a += 1
    n -= 1
b += n

for i, j in enumerate(range(2, 30001, 2)):
    if i == a:
        break
    print(j)

for i, j in enumerate(range(3, 30001, 6)):
    if i == b:
        break
    print(j)

"""
A : 2, 4, 6, ...,  30000 の 15000個
B : 3, 9, 15, ..., 29997 の 5000個
和が6の倍数になるように構成する
Aは, [2, 4] [6] [8, 10] [12]のように, [2, 1, 2, 1, ...]の組みで6の倍数
Bは, [3, 9] [15, 21]のように, [2, 2, 2, 2, ...]の組みで6の倍数
[2, 4, 3, 9]は確定で選ぶ必要がある(全体のGCDは1なので)
そこは7,8行目で確定で選ぶようにして, まずはAから取れるだけ取る
[1, 2, 1, 2, ...]を[3, 3, ...]と解釈する
このとき, Bには2しかないので, 奇数ならば最後の1を必ずAからとる(14行目)
あとは残った数だけBからとる
"""

Submission status: Accepted

Solution code:
n = int(input())

if n == 3:
    print(2, 5, 63)
    exit()

n -= 4
a, b = 2, 2

k = min(n // 3, 4999)
a += k * 3
n -= k * 3

if n % 2 == 1:
    a += 1
    n -= 1
b += n

for i, j in enumerate(range(2, 30001, 2)):
    if i == a:
        break
    print(j)

for i, j in enumerate(range(3, 30001, 6)):
    if i == b:
        break
    print(j)

Submission status: Accepted

Solution code:
import os
import sys
from fractions import gcd
from functools import reduce

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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


def ok(s):
    if reduce(gcd, s) != 1:
        return False
    ok = True
    m = sum(s)
    for a in s:
        # gcd(m-a,a) < gcd(m,a)
        ok &= gcd(m, a) > 1
    return ok


if N == 3:
    ans = {2, 3, 25}
elif N <= 10001:
    ans = {2, 3, 10, 9}
    # 合計が 6 の倍数なので 6 の倍数を足しても条件を満たす
    c = 6
    while c < 30000 and len(ans) < N:
        ans |= {c}
        c += 6
    # 4-5003 まで

    c = 12
    while c + 4 < 30000 and len(ans) < N:
        ans |= {c + 2, c + 4}
        ans -= {c}
        c += 6
    # 10001 まで
else:
    # 2か3で割り切れるやつ全部
    ans = set()
    for i in range(2, 30001):
        if i % 2 == 0 or i % 3 == 0:
            ans.add(i)
    # 6の倍数を引いても条件を満たす
    c = 6
    while c < 30000 and len(ans) > N:
        ans -= {c}
        c += 6
    # 20000-15001までOK

    # 2 mod 6 のやつと 4 mod 6 のやつを引いて 6 の倍数を足す
    c = 4
    while c + 4 < 30000 and len(ans) > N:
        ans -= {c, c + 4}
        ans |= {c + 2}
        c += 6
    # 10002 まで

print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
if n == 3:
    print(2, 5, 63)
    quit()
if n == 4:
    print(2, 5, 20, 63)
    quit()
if n == 5:
    print(2, 5, 20, 30, 63)
    quit()
s = set()
num = ssum = 0
for i in range(2, 30001):
    if i%2 == 0 or i%3 == 0:
        s.add(i)
        ssum += i
        num += 1
    if num == n:
        if ssum % 6 == 2:
            s.discard(8)
            s.add((i//6+1)*6)
        if ssum % 6 == 3:
            s.discard(9)
            s.add((i//6+1)*6)
        if ssum % 6 == 5:
            s.discard(8)
            s.add((i+3)//6*6+3)
        break
print(" ".join(map(str, s)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())

def F(N):
    if N == 3:
        return [2,5,63]
    A2 = [x for x in range(2,30001,2) if x%6 != 0]
    A3 = [x for x in range(3,30001,6)]
    A6 = [x for x in range(6,30001,6)]
    x2 = min(10000,(N-2)//2*2)
    N -= x2
    x3 = min(5000,N//2*2)
    x6 = N - x3
    return A2[:x2] + A3[:x3] + A6[:x6]

answer = F(N)

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

Submission status: Accepted

Solution code:
n=int(input())
if n==3:
  print(2,5,63)
else:
  if n%2==0:
    ans=[3,9]
    cnt=2
    for i in range(30001):
      if i%6==2:
        if i+2<=30000:
          ans.append(i)
          ans.append(i+2)
          cnt+=2
          if cnt==n:
            break
      else:
        continue
    if cnt<n:
      for i in range(12,30001):
        if i%12==3:
          if i+9<=30000:
            ans.append(i)
            ans.append(i+6)
            cnt+=2
            if cnt==n:
              break
        else:
          continue
    if cnt<n:
      for i in range(1,30001):
        if i%6==0:
          ans.append(i)
          cnt+=1
          if cnt==n:
            break
    print(*ans)
  else:
    ans=[3,6,9]
    cnt=3
    for i in range(30001):
      if i%6==2:
        if i+2<=30000:
          ans.append(i)
          ans.append(i+2)
          cnt+=2
          if cnt==n:
            break
      else:
        continue
    if cnt<n:
      for i in range(12,30001):
        if i%12==3:
          if i+9<=30000:
            ans.append(i)
            ans.append(i+6)
            cnt+=2
            if cnt==n:
              break
        else:
          continue
    if cnt<n:
      for i in range(7,30001):
        if i%6==0:
          ans.append(i)
          cnt+=1
          if cnt==n:
            break
    print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
nn=n//6
nr=n%6
if n==3:
  print(2,5,63)
elif n==4:
  print(2,5,20,63)
elif n==5:
  print(2,5,20,30,63)
else:
  Ans=[]
  count=0
  k=1
  while count<n:
    if k%6==2 or k%6==3 or k%6==4 or k%6==0:
      Ans.append(k)
      count+=1
    k+=1
  s=sum(Ans)
  if s%6==2:
    Ans.remove(8)
    Ans.append(6*(k//6+1))
  elif s%6==3:
    Ans.remove(9)
    Ans.append(6*(k//6+1))
  elif s%6==5:
    Ans.remove(9)
    Ans.append(6*(k//6)+4)
  print(*Ans)

Submission status: Accepted

Solution code:
n=int(input())
if n==3:
    ans=[2,5,63]
elif n==4:
    ans=[2,5,20,63]
elif n==5:
    ans=[2,4,6,3,9]
elif n==6:
    ans=[2,4,6,3,9,24]
else:
    for i in range(15000,0,-3):
        if n-i>0 and (n-i)%2==0:
            m2=i
            m3=n-i
            break
    m5=0
    if m3*6-3>30000:
        while m2%5>0:
            m2-=6
            m5+=6
        while m3%5>0:
            m3-=6
            m5+=6
    ans=[]
    for i in range(2,m2*2+1,2):
        ans.append(i)
    for i in range(3,m3*6,6):
        ans.append(i)
    for i in range(5,m5*30,30):
        ans.append(i)
print(" ".join(map(str,ans)))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    if N == 3:
        ans = [2, 5, 63]
    else:
        ans = []
        lst = [2, 3, 4, 6, 8, 9, 10, 12]
        for i in range(N//8):
            ans += list(map(lambda x: x + i*12, lst))
        b = N//8
        m = N % 8
        for i in range(4):
            if m >= 2:
                ans += [b*12+lst[i], b*12+lst[6-i]]
                m -= 2
            elif m == 1:
                ans += [b*12+6]
                break
    print(*ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
k = int(input())
if k == 3:
    print("2 5 63")
elif k == 4:
    print("3 9 2 4")
elif k == 6:
    print("3 9 2 4 8 10")
elif k <= 15002:
    prints = set([3, 9]) 
    k -= 2
    for i in range(int(math.ceil(k / 3))):
        prints.add(i*6+2)
        prints.add(i*6+4)
        prints.add(i*6+6)
    if 3 - k % 3 == 1:
        prints.remove(6)
    if 3 - k % 3 == 2:
        prints.remove(6)
        prints.remove(12)
    print(" ".join([str(item) for item in prints]))
else:
    prints = set() 
    for i in range(5000):
        prints.add(i*6+2)
        prints.add(i*6+4)
        prints.add(i*6+6)
    k -= 15000
    for i in range(int(math.ceil(k / 2))):
        prints.add(i*12+3)
        prints.add(i*12+9)
    if 2 - k % 2 == 1:
        prints.remove(6)
    print(" ".join([str(item) for item in prints]))

Submission status: Accepted

Solution code:
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b

def solve():
    N = int(input())
    ans = []
    if N == 3: ans = [2, 5, 63]
    elif N == 4: ans = [2, 5, 20, 63]
    elif N == 5: ans = [2, 5, 20, 30, 63]
    else:
        count = [0, 0, 0, 0]
        for i in range(N // 4):
            ans.append(6 * i + 2)
            ans.append(6 * i + 3)
            ans.append(6 * i + 4)
            ans.append(6 * i + 6)
            count[0] += 1
            count[1] += 1
            count[2] += 1
            count[3] += 1
        mod = [2, 3, 4, 6]
        for j in range(N % 4):
            ans.append(6 * (N // 4) + mod[j])
            count[j] += 1
        total = sum(ans)
        if total % 6 == 2:
            ans[4] = 6 * count[3] + 6
        elif total % 6 == 3:
            ans[5] = 6 * count[3] + 6
        elif total % 6 == 5:
            ans[5] = 6 * count[2] + 4
    print(" ".join(map(str, ans)))
    return

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
if N == 3:
    print(*[2, 5, 63])
elif N == 4:
    print(*[2, 5, 20, 63])
elif N == 5:
    print(*[2, 5, 20, 30, 63])
else:
    ans = []
    k = 0
    for i in range(2, 30001):
        if i % 2 == 0 or i % 3 == 0:
            ans.append(i)
            k += 1
            if k == N:
                break

    if sum(ans) % 6 == 0:
        print(*ans)
    elif sum(ans) % 6 == 2:
        for j in range(N):
            if ans[j] == 8:
                ans.pop(j)
                break
        ans.append(30000)
        print(*ans)
    elif sum(ans) % 6 == 3:
        for j in range(N):
            if ans[j] == 9:
                ans.pop(j)
                break
        ans.append(30000)
        print(*ans)
    else:
        for j in range(N):
            if ans[j] == 9:
                ans.pop(j)
                break
        ans.append(29998)
        print(*ans)

Submission status: Accepted

Solution code:
N = int(input())
if N == 3:
    print(*[2, 5, 63])
elif N == 4:
    print(*[2, 5, 20, 63])
elif N == 5:
    print(*[2, 5, 20, 30, 63])
else:
    ans = []
    k = 0
    i = 0
    while True:
        ans.append(6 * k + 2)
        i += 1
        if i == N:
            break
        ans.append(6 * k + 3)
        i += 1
        if i == N:
            break
        ans.append(6 * k + 4)
        i += 1
        if i == N:
            break
        ans.append(6 * k + 6)
        i += 1
        if i == N:
            break
        k += 1
    if sum(ans) % 6 == 0:
        print(*ans)
    elif sum(ans) % 6 == 2:
        for j in range(N):
            if ans[j] == 8:
                ans.pop(j)
                break
        ans.append(30000)
        print(*ans)
    elif sum(ans) % 6 == 3:
        for j in range(N):
            if ans[j] == 9:
                ans.pop(j)
                break
        ans.append(30000)
        print(*ans)
    else:
        for j in range(N):
            if ans[j] == 9:
                ans.pop(j)
                break
        ans.append(29998)
        print(*ans)

Submission status: Accepted

Solution code:
import sys
N=int(input())
if N==3:
    print(2,5,63)
    sys.exit()
if N==4:
    print(2,5,20,63)
    sys.exit()
S=[]
L=[0,2,3,4]
for i in range(1,30001):
    j=i%6
    if j in L:
        S.append(i)
    if len(S)==N-1:
        break
s=sum(S)
def f(L):
    return print(' '.join(map(str,L)))
if s%6==0:
    f(S+[30000])
elif s%6==2:
    f(S+[29998])
elif s%6==3:
    f(S+[29997])
elif s%6==5:
    f(S[1:]+[29997,30000])
#print(len(S),s%6)

Submission status: Accepted

Solution code:
from random import sample
n=int(input())
if n==3:
    ans=[2,5,63]
else:
    L=[]
    for i in range(6,30001):
        if i%2==0 or i%3==0:
            L.append(i)
    while True:
        ans=[2,3,4]
        ans+=sample(L,n-3)
        if not sum(ans)%6:
            break
print(*ans)

Submission status: Accepted

Solution code:
n=int(input())
if n==3:
    ans=[2,5,63]
elif n==4:
    ans=[2,5,20,63]
elif n==5:
    ans=[2,3,4,6,9]
else:
    ans=[]
    cnt,s=0,0
    for i in range(2,30001):
        if i%2==0 or i%3==0:
            ans.append(i)
            cnt+=1
            s+=i
        if cnt==n:
            break
    if s%6==2:
        ans.remove(8)
        ans.append((i//6)*6+6)
    elif s%6==3:
        ans.remove(9)
        ans.append((i//6)*6+6)
    elif s%6==5:
        ans.remove(9)
        ans.append(((i+2)//6)*6+4)
print(*ans)

Submission status: Accepted

Solution code:
n = int(input())

if n == 3:
    print(2, 5, 63)
elif n == 4:
    print(2, 5, 20, 63)
elif n == 5:
    print(2, 5, 20, 30, 63)
else:
    a = []
    count = 0
    for i in range(2, 30001):
        if i % 2 == 0 or i % 3 == 0:
            a.append(i)
            count += 1
        if count == n:
            break
    sum_a = sum(a)
    if sum_a % 6 == 0:
        print(*a)
    elif sum_a % 6 == 2:
        a[4] = 30000
        print(*a)
    elif sum_a % 6 == 3:
        a[5] = 30000
        print(*a)
    else:
        a[5] = 29998
        print(*a)

Submission status: Accepted

Solution code:
N = int(input())
if N < 5002:
    if N % 2  == 0:
        sans = [6 * i  + 3 for i in range(N-2)]
        ans = sans + [2,4]
    if N % 2 == 1:
        sans = [6 * i  + 3 for i in range(N-3)]
        ans = sans + [2,4,6]
    if N == 3:
        ans = [2,3,25]
else:
    sans = [6 * i  + 3 for i in range(5000)]
    nis = [2 * i + 2 for i in range(N - 5000 )]
    if (len(nis) * (nis[0] + nis[-1]) //2) % 3 == 1:
        nis[-1] += 2
    elif    (len(nis) * (nis[0] + nis[-1]) //2) % 3 == 2:
        nis[-1] += 2
        nis[-2] += 2
    ans = sans + nis
ans = map(str,ans)
print(" ".join(ans))

Submission status: Accepted

Solution code:
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

n = int(input())
if n >= 15002:
  if n % 2 == 0:
    a = [i*2 for i in range(1,15001)] + [i*6 + 3 for i in range(n - 15000)]
  else:
    a = [i*2 for i in range(1,15000)] + [i*6 + 3 for i in range(n - 14999)]
  print(*a)
elif n == 3:
  print(*[2,5,63])
else:
  b = prime_factors((n-1)*(n-2))
  b.sort()
  c = 0
  for i in b:
    if i >= 3:
      c = i
      break
  d = [i*2 for i in range(1,n-1)] + [c,c*3]
  print(*d)

Submission status: Accepted

Solution code:
data=[]
for i in range(1,30001):
    if i%2==0 or i%3==0:
        data.append(i)
k=int(input())
if k==3:
    print(*[2,5,63])
elif k==4:
    print(*[2,5,20,63])
elif k==5:
    print(*[2,5,20,63,30])
else:
    ans=data[:k]
    sm=sum(ans)
    if sm%6==2:
        ans[4]=30000
    elif sm%6==3:
        ans[5]=30000
    elif sm%6==5:
        ans[5]=29998
    print(*ans)

Submission status: Accepted

Solution code:
n = int(input())
if n == 3:
    res = [2, 5, 63]
elif n == 4:
    res = [2, 5, 20, 63]
elif n == 5:
    res = [2, 5, 20, 30, 63]
else:
    res = [i for i in range(1, 30001)
           if i % 6 not in (1, 5)][:n]
    s = sum(res)
    if s % 6 == 2:
        res.pop(res.index(2))
        res.append(30000)
    elif s % 6 == 3:
        res.pop(res.index(3))
        res.append(30000)
    elif s % 6 == 5:
        res.pop(res.index(3))
        res.append(29998)

print(*res)

Submission status: Accepted

Solution code:
N=int(input())
if N==3:
  print(2,5,63)
  exit()
k=0
a=[]
S=0
for i in range(2,30001):
  if k<N-2:
    if i%2==0 or i%3==0 or i%5==0:
      a.append(str(i))
      k+=1
      S+=i
  elif k==N-2:
    if S%2==0:
      if i%2==0:
        a.append(str(i))
        k+=1
        S+=i
        break
    elif S%2==1:
      if i%2==1:
        if i%3==0 or i%5==0:
          a.append(str(i))
          k+=1
          S+=i
          break
a.append(str(30000-S%30))
print(" ".join(a))

Submission status: Accepted

Solution code:
N = int(input())
N1 = N
candi22 = [20 + 6*i for i in range(4997)]
candi24 = [4 + 6*i for i in range(5000)]
candi3 =  [15 + 6*i for i in range(4998)]
candi6 =  [6 + 6*i for i in range(5000)]
if N == 3:
    print(2, 5, 63)
elif N == 4:
    print(2, 5, 20, 63)
elif N >= 15000:
    ans = [2, 8, 14, 3, 9]
    ans += candi22 + candi24 + candi3 + candi6[:N-15000]
    print(*ans)
else:
    ans = [2, 8, 14, 3, 9]
    N -= 5
    c22 = min(4995, N//3*3)
    N -= c22
    c24 = min(4998, N//3*3)
    N -= c24
    c3 = min(4998, N//2*2)
    N -= c3
    c6 = N
    ans += candi22[:c22] + candi24[:c24] + candi3[:c3] + candi6[:c6]
    print(*ans)

Submission status: Accepted

Solution code:
N = int(input())

if N == 3:
    ans = [2, 3, 25]
else:
    # [合計が6の倍数]を常に満たすように追加する
    if N % 2 == 0:
        As = [2, 10, 3, 9, 4, 8, 6, 12]
    else:
        As = [6, 2, 10, 3, 9, 4, 8, 12]

    ans = []
    for i in range(N):
        ans.append(As[i % 8] + 12 * (i // 8))

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

Submission status: Accepted

Solution code:
N = int(input())

if N == 3:
    ans = {2, 3, 25}
elif N == 4:
    ans = {2, 3, 4, 9}
elif N == 5:
    ans = {2, 3, 4, 6, 9}
else:
    ans = set()
    sumAns = 0
    num = 0
    # 2の倍数もしくは3の倍数を、小さい順に追加する
    for i in range(1, 30001):
        if i % 2 == 0 or i % 3 == 0:
            ans.add(i)
            sumAns += i
            num += 1

        if num == N: break

    # [合計が6の倍数]になるように調整する
    if sumAns % 6 == 2:
        ans.remove(8)
        ans.add(((i + 6) // 6) * 6) # 次の6の倍数
    elif sumAns % 6 == 3:
        ans.remove(9)
        ans.add(((i + 6) // 6) * 6) # 次の6の倍数
    elif sumAns % 6 == 5:
        ans.remove(9)
        ans.add(((i + 2) // 6) * 6 + 4) # 次の6k+4形式の数

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

d_in = lambda: int(stdin.readline())  # N = d_in()


MAX = 30000
N = d_in()

base = [3, 25, 2, 35, 55]
cand = []
for i in range(4, MAX // 2, 2):
    cand.append(i)
    cand.append(MAX - i)

for i in range(9, MAX // 2, 6):
    cand.append(i)
    cand.append(MAX - i)

ans = []
if N < 5:
    ans.extend(base[:3])
    if N == 4:
        ans.append(MAX)
elif N % 2 == 1:
    ans.extend(base)
    ans.extend(cand[:N-5])
else:
    ans.extend(base)
    ans.append(MAX)
    ans.extend(cand[:N-6])
print(*ans)

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
agc022 B
"""

n = int(input())


def nagase(n):
    m, r = divmod(n, 8)
    reg = []
    for i in range(m):
        reg.append(i*12+2)
        reg.append(i*12+3)
        reg.append(i*12+4)
        reg.append(i*12+6)
        reg.append(i*12+8)
        reg.append(i*12+9)
        reg.append(i*12+10)
        reg.append(i*12+12)
    if r == 1:
        reg.append(m*12+6)
    elif r == 2:
        reg.append((m)*12+2)
        reg.append((m)*12+4)
    elif r == 3:
        if m == 0:
            reg = [2, 5, 63]
        else:
            reg.append((m)*12+2)
            reg.append((m)*12+4)
            reg.append((m)*12+6)
    elif r == 4:
        if m == 0:
            reg = [2, 5, 20, 63]
        else:
            reg.append((m)*12+2)
            reg.append((m)*12+4)
            reg.append((m)*12+6)
            reg.append((m)*12+12)
    elif r == 5:
        reg.append((m)*12+2)
        reg.append((m)*12+3)
        reg.append((m)*12+4)
        reg.append((m)*12+6)
        reg.append((m)*12+9)
    elif r == 6:
        reg.append((m)*12+2)
        reg.append((m)*12+3)
        reg.append((m)*12+4)
        reg.append((m)*12+6)
        reg.append((m)*12+9)
        reg.append((m)*12+12)
    elif r == 7:
        reg.append((m)*12+2)
        reg.append((m)*12+3)
        reg.append((m)*12+4)
        reg.append((m)*12+6)
        reg.append((m)*12+8)
        reg.append((m)*12+9)
        reg.append((m)*12+10)
    return reg


print(" ".join(map(str, nagase(n))))

Submission status: Accepted

Solution code:
n=input()
if n==3:
	print '2 5 63'
	quit(0)
if n==4:
	print "2 5 20 63"
	exit(0)
for i in range(n/8):
	print i*12+2, i*12+3, i*12+4, i*12+6, i*12+8, i*12+9, i*12+10, i*12+12,
if n%8==1:
	print n/8*12+6,
if n%8==2:
	print n/8*12+2, n/8*12+4,
if n%8==3:
	print n/8*12+2, n/8*12+4, n/8*12+6,
if n%8==4:
	print n/8*12+2, n/8*12+4, n/8*12+6, n/8*12+12,
if n%8==5:
	print n/8*12+2, n/8*12+3, n/8*12+4, n/8*12+6, n/8*12+9, 
if n%8==6:
	print n/8*12+2, n/8*12+3, n/8*12+4, n/8*12+8, n/8*12+9, n/8*12+10,
if n%8==7:
	print n/8*12+2, n/8*12+3, n/8*12+4, n/8*12+6, n/8*12+8, n/8*12+9, n/8*12+10,
print

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
ans3 = [3*(i*2+1) for i in range(5000)]
ans2 = [2*(i+1) for i in range(15000)]

if N == 3:
    print(2,5,63)
elif N == 4:
    print(2,5,20,63)
elif N == 6:
    print(3,6,9,12,2,4)
elif N == 19999:
    ans = ans2[:14999]+ans3
    print(' '.join(map(str,ans)))
else:
    for x in range(1,2501):
        if (N-x*2)%3 == 0:
            y = (N-x*2)//3
            if 1 <= y <= 5000:
                ans = ans3[:x*2]+ans2[:y*3]
                break
    print(' '.join(map(str,ans)))

Submission status: Accepted

Solution code:
from random import sample
def gcd(x, y):
    if x < y:# x >= y とする
        x, y = y, x
    r = x % y
    res = y if r == 0 else gcd(y, r)
    return res

n = int(input())

nl = []
for j in range(1, 30000 + 1):
    if (j % 2 == 0 or j % 3 == 0 or j % 5 == 0):
        nl.append(j)
len_nl = len(nl)

while True:
    tl = sample(nl, len_nl)
    g = tl[0]
    total = 0
    for j in range(n):
        g = gcd(g, tl[j])
        total += tl[j]
    if total % 30 != 0:
        continue
    if g != 1:
        continue
    break
print(*tl[:n])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

def solve(n:int) -> list:
    x6o2 = [(6*i+2, 6*i+4) for i in range(5000)]
    x6o3 = [(12*i+3, 12*i+9) for i in range(2500)]
    o6 = [6*i+6 for i in range(5000)]
    x6 = []
    for i in range(2500):
        x6.append(x6o3[i])
        x6.append(x6o2[2*i])
        x6.append(x6o2[2*i+1])
    
    ans = []    
    if n == 3:
        ans = [2, 5, 63]
    
    elif n <= 15000:
        idx = n//2
        for i, (mn,mx) in enumerate(x6[:idx]):
            ans.extend([mn,mx])
        if n%2:
            ans = ans + [6]
            
        
    else:
        for i, (mn,mx) in enumerate(x6):
            ans.extend([mn,mx])
        for o6i in o6[:n-15000]:
            ans.append(o6i)
        
    return ans
    
n = ni()
print(*solve(n))

Submission status: Accepted

Solution code:
n = int(input())

if n == 3:
    print(2,5,63)
    exit()
elif n == 4:
    print(2,5,20,63)
    exit()
elif n == 5:
    print(2,5,20,30,63)
    exit()

ans = [8,9,2,3,4,10,6] + [0 for _ in range(n)]
k = 12
i = 7
while i < n:
    ans[i] = k
    ans[i + 1] = k + 2
    ans[i + 2] = k + 3
    ans[i + 3] = k + 4
    i += 4
    k += 6

ans = ans[:n]

temp = sum(ans) % 6

if temp == 2:
    ans[0] = k
elif temp == 3:
    ans[1] = k
elif temp == 5:
    if ans[n - 1] < k - 2:
        ans[1] = k - 2
    else:
        ans[1] = k + 4

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

Submission status: Accepted

Solution code:
n = int(input())
if n==3: print(2,3,25)
elif n<15003:
	print(3,9,end=" ")
	if n%3:
		for i in range(1,n-1): print(2*i,end=" ")
	else:
		print(2,4,end=" ")
		for i in range(4,n): print(2*i,end=" ")
else:
	for i in range(2,30000,2): print(i,end=" ")
	if n%2:
		for i in range(n-14999): print(6*i+3,end=" ")
	else:
		print(30000,end=" ")
		for i in range(n-15000): print(6*i+3,end=" ")

Submission status: Accepted

Solution code:
N = int(input())
s = 0
L = []
a=2
for i in range(N-2):
    while not (a%2==0 or a%3==0 or a%5==0):
        a += 1
    L.append(a)
    s += a
    a += 1
while (not (a%2==0 or a%3==0 or a%5==0)) or (not ((a + s) % 2 == 0 or (a + s) % 3 == 0 or (a + s) % 5 == 0)):
    a += 1
if (a+s)%2 == 0:
    m=2
elif (a+s)%3 == 0:
    m=3
else:
    m=5
L.append(a)
s += a
a = a//m * m + m
while (a+s)%30!=0:
    a += m
L.append(a)
print(" ".join(map(str, L)))