Problem:


Structured Programming

In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you can implement, for example, loops.

Note that use of goto statement is highly discouraged, because it is difficult to trace the control flow of a program which includes goto.

Write a program which does precisely the same thing as the following program (this example is wrtten in C++). Let's try to write the program without goto statements.

void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout n is given in a line.

Output

Print the output result of the above program for given integer n.

Constraints

3 ≤ n ≤ 10000

Sample Input

30

Sample Output

 3 6 9 12 13 15 18 21 23 24 27 30

  Put a single space character before each element.



Sample input:
30


Sample output:
 3 6 9 12 13 15 18 21 23 24 27 30

Submission status: Accepted

Solution code:
import sys
import itertools
import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
lis=[]
for i in range(1,N+1):
    if i%3==0:
        lis.append(i)
    else:
        S=str(i)
        if '3' in S:
            lis.append(i)

ans=' '.join([str(i) for i in lis])
print(' '+ans)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1,n+1):
 x = i
 if x%3==0:
  print(f" {i}",end="")
 else:
  while x>0:
   if x%10==3:
    print(f" {i}",end="")
    break
   else:
    x = x//10
print()

Submission status: Accepted

Solution code:
n = int(input())
s = ''
for i in range(1, n+1):
    if i % 3 == 0:
        s += ' ' + str(i)
        continue
    x = i
    while x:
        if x % 10 == 3:
            s += ' ' + str(i)
            break
        x //= 10
s.rstrip()
print(s)

Submission status: Accepted

Solution code:
n = int(input())

for i in range(1, n+1):
    
    if i % 3 == 0:
        print(f" {i}", end="")
    else:
        x = i
        while (x):
            if x % 10 == 3:
                print(f" {i}", end="")
                break
            else:
                pass
            
            x = x // 10

print()

Submission status: Accepted

Solution code:
n = input()
inl = 3
while int(n) > int(inl) or int(n) == int(inl):
    if int(inl) % 3 == 0:
        print(' ' + str(inl),end='')
        inl += 1
    elif int(int(inl) / 10) == 3:
        print(' ' + str(inl),end='')
        inl += 1
    elif int(inl) % 10 == 3:
        print(' ' + str(inl),end='')
        inl += 1
    elif int((int(inl) / 10) % 10) == 3:
        print(' ' + str(inl),end='')
        inl += 1
    elif int((int(inl) / 100) % 10) == 3:
        print(' ' + str(inl),end='')
        inl += 1
    elif int((int(inl) / 1000) % 10) == 3:
        print(' ' + str(inl),end='')
        inl += 1
    else:
        inl += 1
print('')

Submission status: Accepted

Solution code:
#3 <= a <= 10000
def findthree(a):
    a = str(a)
    l = len(a)
    for i in range(l):
        if a[i]=="3":
            return True

a = int(input())
res = ""
for i in range(a):
    j = i + 1    
    if j%3==0 or findthree(j):
        res += " " + str(j)
print(res)

Submission status: Accepted

Solution code:
n = int(input())

for i in range(1, n+1):

    if i % 3 == 0:
        print(f" {i}", end="")

    else:
        num = i
        while num != 0:
            if num % 10 == 3:
                print(f" {i}", end="")
                break
            else:
                num /= 10
                num = int(num)
print()

Submission status: Accepted

Solution code:
n=int(input())
i = 1
while True:
    x = i
    if x % 3 == 0 :
        print("",i,end="")
        if i+1 <= n :
            i+=1
            continue
        break
    while True:
        if x % 10 == 3 :
            print("",i,end="") 
            break
        x //=10
        if  x!=0 :
            continue
        break
    
    if  i+1 <= n :
        i+=1
        continue
    break
print("")

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    for i in range(1, n + 1):
        if i % 3 == 0:
            print(" ", end="")
            print(i, end="")
        elif "3" in str(i):
            print(" ", end="")
            print(i, end="")
    print()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ans = ""
for i in range(1,n+1):
    if i%3 == 0 or '3' in str(i):
        ans += " " + str(i)
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
L=""
for i in range(1,n+1):
    if i%3==0 or '3' in str(i):
        L +=' '+str(i)
print(L)

Submission status: Accepted

Solution code:
n = int(input())
ans = []
for i in range(1, n+1):
    if i%3 == 0:
        ans.append(str(i))
        continue
    x = i
    while x:
        if x%10 == 3:
            ans.append(str(i))
            break
        x //= 10
print(" " + " ".join(ans))

Submission status: Accepted

Solution code:

def call(n):
    result = ''
    for i in range(1, n + 1):
        x = i
        if x % 3 == 0:
            result += ' ' + str(i)
        else:
            while True:
                if int(x % 10) == 3:
                    result += ' ' + str(i)
                    break
    
                if int(x / 10) > 0:
                    x = int(x / 10)
                else:
                    break
    print(result)

call(int(input()))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(3,n+1):
    if i % 3 == 0 or str(i).find('3') != -1 :
        print(" {}".format(i),end="")
print()

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0:
        print(" {}".format(i), end="")
        continue

    x = i
    while x > 0:
        if x % 10 == 3:
            print(" {}".format(i), end="")
            break
        else:
            x //= 10
print()

Submission status: Accepted

Solution code:
n = int(input())
list = []
for i in range(1,n+1):
    if i%3 == 0 or "3" in str(i):list += [i]
    i += 1
print("",*list)

Submission status: Accepted

Solution code:
def call(n):
    i = 1
    
    while( i <= n ):
        x = i

        if( x % 3 == 0):
            print(" " + str(i), end = "")
            i = i + 1
            continue

        while True:

            if( x % 10 == 3):
                print(" " + str(i) , end = "")
                break
            x = int(x / 10)

            if x == 0 :
                break

        i = i + 1

    print("\n", end = "")

if __name__ == "__main__":

    n = int(input())
    call(n)

Submission status: Accepted

Solution code:
n = int(input())
line = ""
for i in range(n):
    x= i+1
    if x % 3 == 0:
        line += " " + str(i+1)
    else:
        while x > 1:
            if x % 10 == 3:
                line += " " + str(i+1)
                break
            else:
                x = x // 10
print(line)

Submission status: Accepted

Solution code:
n=int(input())
for i in range(1,n+1):
    x=i
    if x%3==0:
        print(' {}'.format(i),end='')
    else:
        include3=False
        while x:
            if x%10==3:
                include3=True
            x//=10
        if include3:
            print(' {}'.format(i),end='')
print()

Submission status: Accepted

Solution code:
n = int(input())
for i in range(3, n+1):
    if i%3==0 or str(i).find('3')!=-1:
        print(' {0}'.format(i), end='')
print()

Submission status: Accepted

Solution code:
n=int(input())
i=1
while(i<=n):
    x=i
    if(x%3==0):
        print(" ",end="")
        print(i,end="")
    else:
        while(x > 0):
            if(x%10==3):
                print(" ",end="")
                print(i,end="")
                break
            x//=10

    i+=1
print()

Submission status: Accepted

Solution code:
import sys

n = int(input())

for i in range (1, n+1):
    if i % 3 == 0:
        print(" ", i, sep="", end="")
    else:
        x = i
        while x > 0:
            if x % 10 == 3:
                print(" ", i, sep="", end="")
                break
            x //= 10

print()

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1,n+1):
    if i%3==0 or '3' in str(i):
        print('',i,end='')
print()

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(3,n+1):
    if _ % 3 == 0:
        print(f" {_}", end="")
    elif "3" in str(_):
        print(f" {_}",end="")
print()

Submission status: Accepted

Solution code:
n = int(input())
ans = ''
for i in range(1, n+1):
    if i % 3 == 0:
        ans += f' {i}'
    elif str(i).count('3') != 0:
        ans += f' {i}'
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

for i in range(1,n+1):
    if i%3 ==0:
        print("",i,end="")
    else:
        j=i
        while j > 0:
            if j%10==3:
                print("",i,end="")
                break
            j=j//10
print()

Submission status: Accepted

Solution code:
import sys

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

for i in range(1, n+1):
    if i % 3 == 0:
        print(' ', i, sep='', end='')
    else:
        x = i
        while x > 0:
            if x % 10 == 3:
                print(' ', i, sep='', end='')
                break
            x //= 10
print()

Submission status: Accepted

Solution code:
n = int(input())
x = 0

for i in range(1,n+1):
    if i%3 ==0:
        print(" %d"%i, end="")
    else:
        x=i
        while(x):
            if x%10 ==3:
                print(" %d"%i, end="")
                break
            x //= 10
print()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    #h,w=list(map(int,input().split()))
    n=int(input())
    ans=[]
    for x in range(1,n+1):
        if x%3==0 or str(x).count("3")>0:
            ans.append(x)
    print("",*ans)
main()

Submission status: Accepted

Solution code:
n = int(input())
i = 1
s = ""
while i <= n:
	if i % 3 == 0:
		s = s + " " + str(i)
	elif "3" in str(i):
	    s = s + " " + str(i)
	i = i + 1
print(s)

Submission status: Accepted

Solution code:
n = int(input())
mat = []

for x in range(1, n+1):
    if x % 3 == 0:
        # 3で割り切れればOK
        mat.append(x)
    else:
        y = x
        # xは保存するため、仮の変数yを置く
        while y != 0:
            if y % 10 == 3:
                # 下1桁が3のときはOKとしてリストに追加
                mat.append(x)
                break
            else:
                # 一桁右シフトして繰り返し。0になったら終了
                y = y // 10

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

Submission status: Accepted

Solution code:
def call(n):
  CHECK_NUM     = 1
  INCLUDE3      = 2
  END_CHECK_NUM = 3
  i = 1
  goto = CHECK_NUM
  while True:
    if goto == CHECK_NUM:
      x = i
      if (x % 3 == 0):
        print(' ' + str(i), end='')
        goto = END_CHECK_NUM
    if goto <= INCLUDE3:
      if (x % 10 == 3):
        print(' ' + str(i), end='')
        goto = END_CHECK_NUM
      else:
        x = int(x / 10)
        if (x != 0):
          goto = INCLUDE3
          continue
    if goto <= END_CHECK_NUM:
      i += 1
      if (i <= n):
        goto = CHECK_NUM
      else:
        print('')
        break

call(int(input()))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(n):
    i += 1
    if i % 3 == 0 or '3' in str(i):
        print(f" {i}", end ="")
print("")

Submission status: Accepted

Solution code:

def Call(n):
    s = ''
    for x in range(1,n+1):
        i = int(x)
        if i%3 == 0:
            temp = ' ' + str(x)
            s += temp
        elif i%10 == 3:
            temp = ' ' + str(x)
            s += temp
        else:
            i = int(i/10)
            while i:
                if i%10 == 3:
                    temp = ' ' + str(x)
                    s += temp
                    break
                i = int(i/10)
    return s


def main():
    n = int(input())
    print(Call(n))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = ""
for i in range(1,int(input()) + 1):
    if i % 3 == 0:
        s += " {0}".format(i)
    else:
        x = i
        while x > 0:
           if x % 10 == 3:
               s += " {0}".format(i)
               break
           x = x // 10
print(s)

Submission status: Accepted

Solution code:
n = int(input())
i = 1
s = ""
while i <= n:
    x = i
    if x % 3 == 0:
        s += " "+str(i)
        i += 1
        continue

    while x > 0:
        if x % 10 == 3:
            s += " " + str(i)
            break
        x = x//10
    i += 1
print(s)

Submission status: Accepted

Solution code:
num = int(input())
for i in range(3,num+1):
    if(i%3==0):
        print("",i,end="")
    elif(i%10==3):
        print("",i,end="")
    elif("3" in str(i)):
        print("",i,end="")
print("")

Submission status: Accepted

Solution code:
x = int(input())
r = ''
for s in range(1, x + 1):
    if s % 3 == 0 or str(s).find('3') != -1:
        r += ' ' + str(s) 
print(r)

Submission status: Accepted

Solution code:
n = int(input())
list3 =[]

def include3(x):
    if x%10==3:
        return True
    if x//10>=1:
        if include3(x//10):
            return True


for i in range(1, n+1):
    if i%3==0:
        list3.append(str(i))
    elif include3(i):
        list3.append(str(i))

print(" ", end="")
print(" ".join(list3))

Submission status: Accepted

Solution code:
n = int(input())
ans = ""
for i in range(1,n+1):
  if i%3 == 0:
    ans += " "+str(i)
  else:
    if i%10 == 3:
      ans += " " + str(i)
    else:
      i = str(i)
      if i.count("3")>0:
          ans += " " + str(i)
print(ans)

Submission status: Accepted

Solution code:
a = input()
for i in range(int(a)):
    if (i+1)%3 == 0 or "3" in str(i+1):
        print(" "+str(i+1),end = "")
print()

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1, n+1):
    if i % 3 == 0 or "3" in str(i):
        print(f" {i}", end="")
print()

Submission status: Accepted

Solution code:
n =int(input())
for i in range(1,n+1):
    if i % 3 == 0 or "3" in str(i):
        print(" {0}".format(i), end="")
print()

Submission status: Accepted

Solution code:
n = int(input())

ans = [str(i) for i in range(1, n+1) if i % 3 == 0 or "3" in str(i)]

print(" " + " ".join(ans))

Submission status: Accepted

Solution code:
keynum = int(input())
for i in range(1,keynum+1):
    if i%3 ==0 or i%10 ==3 :
        print(" "+str(i),end ="")
    else:        
        j = i
        while True:
            if j%10 == 3 :
                print(" "+str(i),end ="")
                break
            else:
                j = j//10
                if j == 0:
                    break

print()

Submission status: Accepted

Solution code:
n = int(input())

for x in range(1, 1 + n):
	if x % 3 == 0 or str(x).find('3') != -1:
	    print(" %d"%x,end="")
    		
print()

Submission status: Accepted

Solution code:
n=int(input())
for i in range(1,n+1):
    if i%3==0:
        print(' '+str(i),end='')
    else:
        if '3' in str(i):
            print('',i,end='')
print()

Submission status: Accepted

Solution code:
l=int(input())
li=[]
for i in range(1,l+1):
    if i%3==0 or '3' in str(i):
        li.append(i)
lis=set(li)
s = " ".join(str(x) for x in lis)
print(" "+s)

Submission status: Accepted

Solution code:
n = int(input())

s = ''
for i in range(1, n+1):
    if i % 3 == 0:
        s += ' ' + str(i)
        continue
    
    dammy = i
    while dammy:
        if dammy % 10 == 3:
            s += ' ' + str(i)
            break
        else:
            dammy //= 10
print(s)

Submission status: Accepted

Solution code:
BIG_NUM = 2000000000


N = int(input())
x = 0

for i in range(1,N+1):

    if i%3 == 0:
            print(" %d"%i,end = "");
    else:
        x = i
        while (x):
            if x%10 == 3:
                print(" %d"%i,end = "")
                break
            x //= 10
print()

Submission status: Accepted

Solution code:
def include3(x):
    if (x % 10 == 3):
        return True
    else:
        x //= 10
        if (x>0):
            return include3(x)
        else:
            return False

n = int(input())

s = ''
for i in range(1,n+1):
    if (i % 3 == 0):
        s += ' '+str(i)
    elif (include3(i)):
        s += ' '+str(i)
print(s)

Submission status: Accepted

Solution code:
n = int(input())
l =[]
for i in range(3,n+1):
    if i%3 == 0 or "3" in str(i) :
        l.append(i)
print("", *l)

Submission status: Accepted

Solution code:
n=int(input())
for i in range(1,n+1):
    if i%3==0:
        print("",i,end="")
    else:
        a=i
        while a!=0:
            if a%10==3:
                print("",i,end="")
                break
            a//=10
            
print()

Submission status: Accepted

Solution code:
import sys
i=int(input())
k=''
for j in range(1,i+1):
  if j%3==0 or '3' in str(j):
    k+=" "+str(j)
    
print(k)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(3, n+1):
    if i % 3 == 0 or '3' in str(i):
        print(" ", i, sep='', end='')
print("")

Submission status: Accepted

Solution code:
x = int(input())
for i in range(1,x+1):
    if(i % 3 == 0):
        print(" {}".format(i),end="")
    elif("3" in str(i)):
        print(" {}".format(i),end="")
print()

Submission status: Accepted

Solution code:
N = int(input())

for i in range(1, N+1):
    
    if i % 3 == 0:
        print(" {}".format(i), end="")
        continue
    
    if "3" in str(i):
        print(" {}".format(i), end="")
        continue

print()

Submission status: Accepted

Solution code:
n = int(input())
tmp = ''
for x in range(3, n + 1):
    if x % 3 == 0 or str(x).find('3') >= 0:
        tmp += ' ' + str(x)
print(tmp)

Submission status: Accepted

Solution code:
n = int(input())

for i in range(1, n + 1) :
    if i % 3 == 0 or "3" in str(i) :
        print(" ", i, end = "", sep = "")
print()

Submission status: Accepted

Solution code:
N = int(input())
nlst =list()
for i in range(1,N+1):
    if i % 3 == 0:
        nlst.append(i)
    else:
        j = i
        while j > 1 :
            if j % 10 == 3 :
                nlst.append(i)
                break
            j = j//10
s = str()
for j in nlst:
    s += " " + str(j)
print(s)

Submission status: Accepted

Solution code:
def include3(x, i):
	if x % 10 == 3:
		print(' ' + str(i) , end='')
	else:
		x = int(x/10)
		if x:
			include3(x, i)

n = int(input())

for i in range(1, n + 1):
	x = i
	if x % 3 == 0:
		print(' ' + str(i), end='')
	else:
		include3(x, i)

print('')

Submission status: Accepted

Solution code:
n = int(input())

for x in range(1,n+1):
    num = x
    if(x % 3 == 0):
        print(" %d" %x, end="")
        continue
        
    while True:
        if(x % 10 == 3): # 一の位が３であるかの判定
            print(" %d" %num, end = "")
            break
        
        x //= 10
        if(x == 0): 
            break

        if(x % 10 == 3):
            print(" %d" %num, end ="")
            break
print()

Submission status: Accepted

Solution code:
def include3(x):
    while True:
        if x % 10 == 3:
            return True
        else:
            x = int(x / 10)
        if x == 0:
            return False

n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0 or include3(i):
        print(' %d' %i, end = '')
print('')

Submission status: Accepted

Solution code:
N = int(input())

for i in range(1,N+1):
    if i % 3 == 0:
        print(' '+str(i),end="")
    else:

        check_num = str(i)
        if '3' in check_num:
            print(' '+check_num,end="")

print("")

Submission status: Accepted

Solution code:
n=int(input())
s=""
c=n
for i in range(1,c+1):
    if i%3==0 or "3" in str(i):
        s+=" "+str(i)
print(s)

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
for i in range(1,n+1):
    if i%3==0:
        ans.append(i)
    elif "3" in str(i):
        ans.append(i)
print("",*ans)

Submission status: Accepted

Solution code:
n = int(input())

for i in range(1, n+1):
    x = i
    if x % 3 == 0:
        print(' ', i, sep='', end='')
        continue
    while x > 0 :
        if x % 10 == 3:
            print(' ', i, sep='', end ='')
            break
        x //= 10
print()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n = int(input())

for i in range(1,n+1):
    x = i
    if(x % 3 == 0):
        print(" %d"%x, end ='')
    else:
        while(x):
            if(x % 10 == 3):
                print(" %d"%i, end='')
                break
            x //= 10
print('')



# 3 6 9 12 13 15 18 21 23 24 27 30 31 32 33 34 35 36 37 38 39 42 43 45 48 51 53 54 57 60

Submission status: Accepted

Solution code:

s = ""
for i in range(1,int(input())+1):
    if i%3 == 0 or ("3" in str(i)):
        s +=(" " + str(i))

print(s)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1,n+1):
    if i % 3 == 0 or str(i).find("3") != -1:
        print(" %d" % (i),end="")
print()

Submission status: Accepted

Solution code:
n=int(input())
for i in range(1,n+1):
    if i%3==0:print(" %d"%i,end="")
    else:
        x=i
        while x:
            if x%10==3:
                print(" %d"%i,end="")
                break
            x //=10
print()

Submission status: Accepted

Solution code:
# input
num = int(input())

# calculate order
order = 0
for i in range(5):
    if 0 < num // 10**i <= 9:
        order = i

# loops
s = []
for j in range(1, num+1):
    if j % 3 == 0 or '3' in str(j):
        s.append(j)

print(' ', end='')
print(*s)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(3, n + 1):
    if not i % 3 or "3" in str(i):
        print("", i, end="")
print()

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0:
        print(f' {i}', end='')
        continue
    x = i
    while x > 0:
        if x % 10 == 3:
            print(f' {i}', end='')
            break
        x //= 10

print()

Submission status: Accepted

Solution code:
for i in range(1,int(input())+1):
    ky=False
    if i%3==0:
        ky=True
    else:
        j=i
        while j:
            if j%10==3:
                ky=True;break
            j//=10
    if ky:
        print(' ',i,sep='',end='')
print()

Submission status: Accepted

Solution code:
def call(n):
    i = 1

    while True:
        x = i
        if x % 3 != 0:
            while True:
                if x % 10 == 3:
                    print(" %d" % i, end='')
                    break
                x //= 10
                if x == 0:
                    break
        else:
            print(" %d" % i, end='')
        i += 1
        if i > n:
            break
    print()


call(int(input()))

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1, n+1):
  x = i
  if x%3 == 0:
    print("", i, end = "")
  else:
    while(x > 0):
      if x%10 == 3:
        print("", i, end = "")
        break
      else:
        x = x//10
print()

Submission status: Accepted

Solution code:
import sys
if sys.platform=="ios":
	sys.stdin=open("input_file.txt")

n=int(input())
ans=""
print(end=" ")
for i in range(1,n+1):
	if i%3==0:
		ans+=str(i)+" "
		continue
	
	a=i//10000
	b=(i-10000*a)//1000
	c=(i-10000*a-1000*b)//100
	d=(i-10000*a-1000*b-100*c)//10
	e=(i-10000*a-1000*b-100*c-10*d)
	
	if a==3 or b==3 or c==3 or d==3 or e==3:
		ans+=str(i)+" "
		
print(ans[:-1])

Submission status: Accepted

Solution code:
num = int(input())
for i in range(1, num + 1):
    x = i
    if x % 3 == 0:
        print(f' {i}', end='')
    elif x % 10 == 3:
        print(f' {i}', end='')
    else:
        while x > 0:
            x = x // 10
            if x % 10 == 3:
                print(f' {i}', end='')
                break
print()

Submission status: Accepted

Solution code:
x = int(input())
i = 1

while True:
    if i <= x:
        if i % 3 == 0:
            print(' {}'.format(i), end='')
        elif str(i).find('3') != -1:
            print(' {}'.format(i), end='')
    else:
        break
    i += 1
print()

Submission status: Accepted

Solution code:
n = int(input())
ans = []

for i in range(3, n + 1):
    if i % 3 == 0:
        ans.append(' ' + str(i))
    elif '3' in str(i):
        ans.append(' ' + str(i))

print(''.join(ans))

Submission status: Accepted

Solution code:
n = int(input())
_ = list()
for i in range(1,n+1):
    if i % 3 == 0 or "3" in str(i):
        _.append(str(i))
        continue
print(" " + " ".join(_))

Submission status: Accepted

Solution code:
n = int(input())
for _ in range(3,n+1):
    flag = False
    if _ % 3 == 0:
        print(" ",_,end='',sep='')
        flag = True
    for i in list(str(_)):
        if i == '3' and flag == False:
            print(" ",_,end='',sep='')
            break
print()

Submission status: Accepted

Solution code:
n = int(input())

for i in range(1,n+1):
    x = i
    if i % 3 == 0:
        print(" ",end="")
        print(i,end="")
    else:
        while True:
            if x == 0:
                break
            if x % 10 == 3:
                print(" ",end="")
                print(i,end="")
                break
            x = int(x/10)

print("")

Submission status: Accepted

Solution code:
n = int(input())
i = 1
while i <= n:
    x = i
    if x % 3 == 0 or x % 10 == 3:
        print(f" {i}", end='')
    else:
        while x:
            x //= 10
            if x % 10 == 3:
                print(f" {i}", end='')
                break
    i += 1
print()

Submission status: Accepted

Solution code:
#coding: utf-8

n = int(input())
for j in range(n):
    i = j + 1
    iStr = str(i)
    if i % 3 == 0 or '3' in iStr:
        print(' %d' % i, end = '')
print('')

Submission status: Accepted

Solution code:

def Check_Num(i):
    x = i
    if(x%3==0):
        print(" ",i,sep="",end="")
        return False
    return True

def Include_3(i,j):
    x = i
    y = j
    
    if(x%10==3):
        print(" ",j,sep="",end="")
        return True 
    x = (int)(x/10)       
    if(x!=0):
        Include_3(x,y)

s = input()
n = int(s)

for i in range(1,n+1):
    boolean = Check_Num(i)

    if boolean:
        Include_3(i,i)

print()

Submission status: Accepted

Solution code:
def test():

	n = int(input())

	for i in range(1,n+1):
		if i % 3 == 0:
			print(f" {i}",end='')
			continue
		elif i % 10 == 3:
			print(f" {i}",end='')
			continue
		elif (i // 10) % 10 == 3:
			print(f" {i}",end='')
			continue
		elif (i // 100) % 10 == 3:
			print(f" {i}",end='')
			continue
		elif (i // 1000) % 10 == 3:
			print(f" {i}",end='')
			continue
		elif (i // 10000) % 10 == 3:
			print(f" {i}",end='')
			continue


	print()

if __name__ == "__main__":
	test()

Submission status: Accepted

Solution code:
def call(n):
    i = x = 1
    mode = 0

    while i <= n :
        if mode == 0:
            x = i
            if x % 3 == 0:
                print(" "+ str(i) ,end="")
            else:
                mode = 1
                continue
        else:
            if x % 10 == 3:
                print(" " + str(i) ,end="")
            else:
                x = x // 10
                if x :
                    continue

        mode = 0
        i+=1

    print()

call(int(input()))

Submission status: Accepted

Solution code:
n=int(input())
a=""
for i in range(1,n+1):
    if "3" in str(i):
        a=a+" "+str(i)
    elif i%3==0:
        a=a+" "+str(i)
print(a)

Submission status: Accepted

Solution code:
n = int(input())

print(' ' + ' '.join([str(i) for i in range(1, n+1) if i % 3 == 0 or '3' in str(i)]))

Submission status: Accepted

Solution code:
print(" " + " ".join([str(i) for i in range(1, int(input()) + 1) if i%3 == 0 or '3' in str(i)]))

Submission status: Accepted

Solution code:
n=int(input())
l=[]
for i in range(1,n+1):
    x=i
    if (x%3)==0:
        l.append(str(i))
    else:
        while(1):
            if x==0:
                break
            elif (x%10)==3:
                l.append(str(i))
                break
            else:
                x=x//10    
l=' '.join(l)
print(' '+l)

Submission status: Accepted

Solution code:
n = int(input())
A = ""
for i in range(1,n+1):
    if i%3==0:
        A +=" "+str(i)
    elif "3" in str(i):
        A +=" "+str(i)
print(A)

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1, n+1):
	if (i % 3 == 0) or ('3' in str(i)):
		print(' '+str(i), end = '')
print()

Submission status: Accepted

Solution code:
a = int(input())
for i in range(1, a + 1):
    if i % 3==0 or '3' in str(i):
        print(' ' + str(i) , end='')
    if i == a:
        print('')

Submission status: Accepted

Solution code:
n = int(input())
print_list = []
for i in range(1, n+1):
    tmp_val = i
    # 3の倍数
    if tmp_val % 3 == 0:
        print_list.append(i)
    else:
        while tmp_val != 0:
            # 3が含まれる
            if tmp_val % 10 == 3:
                print_list.append(i)
                break
            else:
                tmp_val = tmp_val // 10

for i in range(len(print_list)):
    print(" ", print_list[i], sep="", end="")
print("")

Submission status: Accepted

Solution code:
n = int(input())
ans = []
for i in range(1,n+1):
    if i%3 == 0:
        ans.append(i)
        continue
    tmp = i
    while tmp != 0:
        if tmp % 10 == 3:
            ans.append(i)
            flg = True
            break
        else:
            tmp //= 10
        

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

Submission status: Accepted

Solution code:
def CHECK_NUM(n):
    for d in range(len(n)):
        if n[d]=="3":
            return True
    return False
 
num = int(input())
str=""
for d in range(3,num+1):
    s = "%d"%(d)
    if d%3==0 or CHECK_NUM(s):
        str+=" %d"%(d)
print(str)

Submission status: Accepted

Solution code:
n=int(input())
for i in range(1,n+1):
    if i%3==0 or i%10==3 or "3" in str(i):
        print(f" {i}",end='')
print()

Submission status: Accepted

Solution code:
l = [];n = int(input())
for i in range(1,n+1):
    x = i
    if x%3==0 or x%10==3:
        l.append(i)
    elif x%10!=3:
        while(x):
            x = int(x/10)
            if(x%10==3):
                l.append(i);break;
for i in range(len(l)):
    print(" %d"%l[i],end = '')
print()

Submission status: Accepted

Solution code:
n = int(input())
for i in range(1, n + 1):
    x = i
    if x % 3 == 0:
        print(" " + str(i), end="")
    else:
        while x != 0:
            if x % 10 == 3:
                print(" " + str(i), end="")
                break
            x //= 10
print()

Submission status: Accepted

Solution code:
n=int(input())
x=""
for i in range(2,n+1):   
    if i%3==0 or "3" in str(i):
        print(" {}".format(i), end="")
print()

Submission status: Accepted

Solution code:
n = int(input())

for i in range(n+1)[1:]:
  if i % 3 == 0:
    print(" {}".format(i),end="")
    continue

  if i % 10 == 3:
    print(" {}".format(i),end="")
    continue

  x = i
  while x > 1:
    x = int(x / 10)
    if x % 10 == 3:
      print(" {}".format(i),end="")
      break


print()

Submission status: Accepted

Solution code:
print('', *[i for i in range(3, int(input()) + 1) if i % 3 == 0 or '3' in str(i)])

Submission status: Accepted

Solution code:
n=int(input())
for i in range(1, n+1):
    if i%3 ==0 or "3" in str(i):
        print(f" {i}",end="")
print()

Submission status: Accepted

Solution code:
n = int(input())
tmp = 0
lis = []
for i in range(1, n+1):
    if i % 3 == 0:
        lis.append(i)
    else:
        tmp = i
        while i > 0:
            if i % 10 == 3:
                lis.append(tmp)
                break
            else:
                i //= 10
print(" ", end="")
print(*lis)