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:
n = int(input())

def call(n):
    i = 0
    while True:
        i += 1
        if i > n:
            break
        x = i
        if x % 3 == 0:
            print(' ' + str(i), end = '')
            continue

        while True:
            if int(x) % 10 == 3:
                print(' ' + str(i), end = '')
                break
            x /= 10
            if x == 0:
                break
            
    print()
    
call(n)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=[]
n=int(input())
i=1
c=0
while i <= n:
    if c==0:
        x=i
        if x%3==0:
            a.append(i)
            i+=1
            continue
    c=0
    if x%10==3:
        a.append(i)
        i+=1
        continue
    x//=10
    if x == 0:
        i+=1
        continue
    else:
        c=1
print(' ', end='')
print(*a)

Submission status: Accepted

Solution code:
n=int(input())
a,c,i=[],0,1
while i <= n:
    if c==0:
        x=i
        if x%3==0:
            a.append(i)
            i+=1
            continue
    c=0
    if x%10==3:
        a.append(i)
        i+=1
        continue
    x//=10
    if x == 0:
        i+=1
        continue
    else:
        c=1
print(' ', end='')
print(*a)

Submission status: Accepted

Solution code:
n=int(input())
a,c,i=[],0,1
while i <= n:
    if c==0:
        x=i
        if x%3==0:
            print(' '+str(i), end='')
            i+=1
            continue
    c=0
    if x%10==3:
        print(' '+str(i), end='')
        i+=1
        continue
    x//=10
    if x == 0:
        i+=1
        continue
    else:
        c=1
print()

Submission status: Accepted

Solution code:
n=int(input())
c,i=0,1
while i <= n:
    if c==0:
        x=i
        if x%3==0:
            print(' '+str(i), end='')
            i+=1
            continue
    c=0
    if x%10==3:
        print(' '+str(i), end='')
        i+=1
        continue
    x//=10
    if x == 0:
        i+=1
        continue
    else:
        c=1
print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def g(n):
    for i in range(1, n+1):
        if i % 3 == 0:
            yield " {}".format(i)
            continue
        x = i
        while x != 0:
            if x % 10 == 3:
                yield " {}".format(i)
                break
            x //= 10

n = int(input())
print("".join(g(n)))

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
for i in range(3, 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())
ans = ''
for i in range(1, n+1):
 if i%3 == 0:
  ans += " " + str(i)
 elif i%10 == 3:
  ans += " " + str(i)
 else:
  div = i
  while div//10:
   div = div//10
   if div%10 == 3:
    ans += " " + str(i)
    div = 0
print(ans)

Submission status: Accepted

Solution code:
# (c) midandfeed
n = int(input())
	
for i in range(1, n+1):
	x = i
	if (x%3==0) or (x%10==3):
		print(" {}".format(x), end='')
	else:
		temp = x
		while(temp>0):
			if (temp%10==3):
				print(" {}".format(x), end='')
				break
			else:
				temp = temp//10
print()

Submission status: Accepted

Solution code:
num = int(input())

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

print()

Submission status: Accepted

Solution code:
num = int(input())

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

print()

Submission status: Accepted

Solution code:
num = int(input())

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

print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
result = []
def check(x, y, remnant):
    return x % y == remnant

for i in range(1, n + 1):
    x = i
    if check(x, 3, 0):
        result.append(i)
        continue
    for j in range(len(str(x))):
        if check(x, 10, 3):
            result.append(i)
            break
        x //= 10
print(' ' + ' '.join(map(str, result)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n = int(input())
for i in range(1, n + 1):
    if i % 3 == 0:
        sys.stdout.write(' ')
        sys.stdout.write(str(i))
    else:
        x = i
        for j in range(0, 5):
            if x % 10 == 3:
                sys.stdout.write(' ')
                sys.stdout.write(str(i))
                break
            x //= 10

print('')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    ans = []
    i = 1
    while 1:
        if i <= n:
            if i % 3 == 0:
                ans.append(i)
            else:
                hoge = list(str(i))
                if "3" in hoge:
                    ans.append(i)
            i += 1
        else:
            break
    
    print(" ", end = "")
    for x in range(len(ans)):
        if x != len(ans) - 1:
            print(ans[x], end = " ")
        else:
            print(ans[x])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

n = int(raw_input())
#n = 30


for i in range(1, n+1):
	if i % 3 == 0:
		sys.stdout.write(" {:}".format(i))
	elif str(i).find('3') > -1:
		sys.stdout.write(" {:}".format(i))
print("")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    _list = list(range(1,n+1))
    for x in _list:
        if x % 3 == 0 or any(list(map(lambda x: x == 3, list(map(int,list(str(x))))))):
            print(' %d' %  x, end = '')
    print()
    

main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    _list = list(range(1,n+1))
    for x in _list:
        if x % 3 == 0 or any(list(map(lambda x: int(x) == 3, list(str(x))))):
            print(' %d' %  x, end = '')
    print()
    

main()

Submission status: Accepted

Solution code:
def call(n):
    i = 1
    while i <= n:
        if i % 3 == 0:
            print(' %d' % i, end='')
        else:
            x = i
            while x > 0:
                if x % 10 == 3:
                    print(' %d' % i, end='')
                    break
                x = int(x/10)
        i += 1
    print('')

line = input()
n = int(line)

call(n)

Submission status: Accepted

Solution code:
import sys

def main():
    lines = sys.stdin.readlines()
    input_num = 0
    ans = []
    for line in lines:
        # print(line)
        # rm '\n' from string of a line
        line = line.strip('\n')
        input_num = int(line)
        n = input_num
        # print input_num
        print "",
        index_num = 1
        flag = 0
        while True:
            # END CHECKNUM
            if index_num != 1 or flag == 1:
                if (index_num + 1) > n:
                    break
                else:
                    index_num += 1 # Go on below
            else:
                flag = 1
            x = index_num
            if x % 3 == 0:
                print index_num,
                continue
            if x % 10 == 3:
                print index_num,
                continue
            else:
                while x > 0:
                    x /= 10
                    if x % 10 == 3:
                        print index_num,
                        break

        break


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
print('',*[i for i in range(3,int(input())+1)if i%3==0 or'3'in str(i)])

Submission status: Accepted

Solution code:
# -*-coding:utf-8

#import fileinput
import math

def main():

    n = int(input())

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

    print('')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#????????§???????????????????????????????????????????????????????????¨???????????¨???????????????
#0????????£????????????????????????????????????
#?????????????????¨??¶???????°??????????
#????????????
#??????????????¢??°??????????????????????????????????????????????????????????????????????????\????????????????????????print??????????????????????????????????????????
#?????????????????????????????????????????????3????????°????¢???????????????£??????????????????????????????????????????????????????????????????
#?????????????????????
#?????????????????????????????????????????°???????????????????????????????????????????????¨?????????
#??????????????????????????¨??£????????????????????????????????????????¶??????????
x = int(input())

    
i = 1
y = i
n = []

#10??§?????£???3????????????3?????????????????????????????????????????????10??§???????¶???????1???????????§?¶???????
while i <= x:
    if y % 10 == 3 or y / 3 == 1:
        n.append(i)
        i += 1
        y = i
    else:
        y //= 10
        if y == 0:
            #?????????3????????°????????§??????????????????????????????
            if i % 3 == 0:
                n.append(i)
                i += 1
                y = i
            else:
                i += 1
                y = i
                
print("", end=" ")

i = 0
while i < int(len(n))-1:
    print(n[i], end=" ")
    i += 1
    
print(n[i])
#print("end")

Submission status: Accepted

Solution code:
import sys
n=int(input())
a=[]
for i in range(1,n+1):
    if (i%3==0):
        a.append(i)
    else:
        j=str(i)
        for k in range(len(j)):
            if j[k]=="3":
                a.append(i)
                break
for i in a:
    sys.stdout.write(" {0}".format(i))
sys.stdout.write("\n")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def threeDivCheck(x):
  if x % 3 == 0: return x
  return 0

def threeIncludeCheck(x):
  y = x
  while y!=0:
    if y%10 == 3:
      return x
    y=int(y/10)
  return 0

def main():
  n = int(input())
  p = 0
  for i in range(n+1):
    p = threeDivCheck(i)
    if p:
      print(' {}'.format(p), end='')
    else:
      p=threeIncludeCheck(i)
      if p:
        print(' {}'.format(p), end='')
  print()

main()

Submission status: Accepted

Solution code:
def main():
    """
    n=30
     3 6 9 12 13 15 18 21 23 24 27 30
    """
    n = int(input())
    for i in range(1, n + 1):
        x = i
        if x % 3 == 0:
            print("", i, end="")
            continue

        while x > 0:
            if x % 10 == 3:
                print("", i, end="")
                break

            x //= 10

    print("")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def CheckNum(n, x, i):
	x = i
	if x % 3 == 0:
		print(" %d"%(i), end="")
		return 2, i, x
	return 1, i, x

def Include3(n, x, i):
	if x % 10 == 3:
		print(" %d"%(i), end="")
		return 2, i, x
	x = int(x/10)
	if x != 0:
		return 1, i, x
	return 2, i, x

def EndCheckNum(n, x, i):
	i += 1
	if i <= n:
		return 0, i, x
	print("")
	return 3, i, x
	
def call(n):
	counter = 0
	i = 1
	x = 1
	func = [CheckNum, Include3, EndCheckNum]
	while counter != 3:
		counter, i, x = func[counter](n, x, i)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
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())
list = []
for i in range(3,n+1):
    if i % 3 == 0 or "3" in str(i):
        list.append(i)
print(end = ' ')
print(*list)

Submission status: Accepted

Solution code:
def check(st):
    for d in range(len(st)):
        if st[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(s):
        str+=" %d"%(d)
print(str)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

result = [""]
for i in range(3, n + 1):
    if i % 3 == 0:
        result.append(i)
    elif "3" in list((str(i))):
        result.append(i)
print(*result)

Submission status: Accepted

Solution code:
def call(a):
    if a % 3 == 0:
        return True

    while a != 0:
        if a % 10 == 3:
            return True

        a //= 10

    return False

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

    for i in range(1, n + 1):
        if call(i):
            print(" {0}".format(i), end="")

    print("")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8
import sys
def call(n):
    i = 1
    sys.stdout.write(' ')
    while i <= n:
        x = i
        if x % 3 == 0:
            print i, 
            if i <= n:
                i += 1
                continue
        while x != 0:
            if x % 10 == 3:
                print i,
                if i <= n:
                    break
            x = int(x / 10)
        i += 1
    else:
        print
n = input()
call(n)

Submission status: Accepted

Solution code:
n = int(input())

i = 1
while i <= n:
    x = i
    if x % 3 == 0:
        print(" {:d}".format(i),end="")
    else:
        while x:
            if x % 10 == 3:
                print(" {:d}".format(i),end="")
                break
            x = x // 10
    i += 1
print("")

Submission status: Accepted

Solution code:
a = int(input())

res = ''

i = 1
while True:
    x = i
    if x % 3 == 0:
        res += " " + str(i)
    else:
        while True:
            if x % 10 == 3:
                res += " " + str(i)
                break
            x = x // 10
            if x == 0:
                break
    i += 1
    if i > a:
        break

print(res)

Submission status: Accepted

Solution code:
for i in range(1, int(input()) + 1):
    if i % 3 == 0 or "3" in list(str(i)):
        print("", i, end="")
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()) 
print(' ', end='') 
print(*[i for i in range(1, 1 + n) if i % 3 == 0 or '3' in str(i)])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def call(n):
    ret = ""
    for i in range(1, int(n)+1):
        if 0 == i % 3:
            ret += " " + str(i)
        elif -1 != str(i).find("3"):
            ret += " " + str(i)

    return ret

if __name__ == "__main__":
    n = input()
    ret = call(n)
    print (ret)

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(' %d' % i, end='')
print()

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 += " {}".format(i)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8

n = int(input())

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

    for j in range(6):
        if int(x / (10**j)) % 10 == 3:
            print(" " + str(x), end = '')
            break
print("")

Submission status: Accepted

Solution code:
num = int(input())
result=""
for i in range(1,num+1):
    if i%3==0:
        result+=" "+str(i)
    elif str(i).find("3")!=-1:
        result+=" "+str(i)
print(result)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-

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())
for i in range(n):
    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())
ans = ""
for i in range(1, n + 1):
    if(i % 3 == 0):
        ans += " " + str(i)
        continue
    x = i
    while(x):
        if(x % 10 == 3):
            ans += " " + str(i)
            break
        x //= 10
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
i = 1
a = ''
while i <= n:
    x = i
    if x % 3 == 0:
        a += ' ' + str(i)
    elif x % 10 == 3:
        a += ' ' + str(i)
    else:
        x /= 10
        x = int(x)
        while x:
            if x % 10 == 3:
                a += ' ' + str(i)
                break
            x /= 10
            x = int(x)
    i += 1
print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
for i in range(num):
    i += 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(1, n+1) :
    x = i
    if (x%3 == 0) :
        print(' %d' % i, end = '')
    else :
        while (x) :
            if (x%10 == 3) :
                print(' %d' % i, end = '')
                break
            x //= 10
print('')

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def multiple_3(num):
    if num % 3 == 0:
        print(" {}".format(num), end="")
    else:
        included_3(num)

def included_3(num):
    if "3" in str(num):
        print(" {}".format(num), end="")
        
n = int(input())
for num in range(3, n+1):
    multiple_3(num)
print()

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys

def main():
    n = int(raw_input())
    for i in range(3, n+1):
        if three(i):
            sys.stdout.write(' {}'.format(i))
    print

def three(i):
    if i%3 == 0:
        return True

    while i > 0:
        if i%10 == 3:
            return True
        i /= 10

    return False

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def Check_Num(n):

    for i in range(1,n + 1):
        x = i
        if (x % 3 == 0):
            print(' {}'.format(i),end = '')
            continue
        elif (x % 10 == 3):
            print(' {}'.format(i),end = '')
            continue
        x //= 10
        while (x > 0):
            if (x % 10 == 3):
                print(' {}'.format(i),end = '')
                break
            x //= 10
    print()
if __name__ == '__main__':
    n = int(input())
    Check_Num(n)

Submission status: Accepted

Solution code:
n = int(input())
ans = ''
i = 1
while i <= n:
    x = i
    if (x % 3) == 0:
        ans += ' ' + str(i)
        i += 1
    elif (x % 10) == 3:
        ans += ' ' + str(i)
        i += 1
    else:
        while True:
            x = (x // 10)
            if x == 0:
                i += 1
                break
            elif (x % 10) == 3:
                ans += ' ' + str(i)
                i += 1
                break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(1, n+1):
    if i % 3 == 0:
        l.append(i)
    else:
        j = i
        while j > 0:
            if j % 10 == 3:
                l.append(i)
                break
            else:
                j //= 10

for p in l:
    print(" " + str(p), end="")
print()

Submission status: Accepted

Solution code:



n=int(input())

d=[]
for i in range (3,n+1):
     if i%3==0 or "3"in str(i):
          d.append(i)
print(' ',end="")
print(*d)

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:
n = int(input())
for i in range(3, n + 1):
  if i % 3 == 0 or "3" in str(i):
    print(" %d" % i, end = "")
print("")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
num_list = [i for i in range(1,n+1)]
num2_list = [i for i in num_list if i%3==0]#3で割り切れる値
list_str = [s for s in map(str,num_list) if '3' in s]#3が含まれる場合
list_in = list(map(int,list_str))#list変換
list_uniq = list(set(num2_list+list_in))
list_uniq.sort()
print(' '+' '.join(str(i) for i in list_uniq))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from functools import reduce

n = int(input())
i = 1

while True:

    a = [int(x) for x in list(str(i))]

    if 3 in a:
        print(" {0}".format(int(reduce(lambda x, y: x + y, [str(x) for x in a]))), end='')
    elif sum(a) % 3 == 0:
        print(" {0}".format(int(reduce(lambda x, y: x + y, [str(x) for x in a]))), end='')

    i += 1
    if i > n:
        print()
        break

Submission status: Accepted

Solution code:
num = int(input())
targetNumList = []
for i in range(3, num + 1):
    if i % 3 == 0:
        targetNumList.append(i)
    elif str(i).__contains__('3'):
        targetNumList.append(i)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def include3(n):
	cond = 0
	while True:
		if n%10==3:
			cond = 1
			return cond
		elif n>9:
			n //= 10
		else:
			return cond

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

Submission status: Accepted

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

while i <= n:
	if i % 3 == 0 or "3" in str(i):
		print(" ",end='')
		print(i,end='')
	i += 1
print()

Submission status: Accepted

Solution code:
def check(num):
    n = str(num)
    for i in range(len(n)):
        if n[i] == '3': return True
    return False

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())
b = []
print(" ",end="")
for i in range(1, a+1, 1):
    if "3" in str(i):
        b.append(i)
    elif i % 3 == 0:
        b.append(i)
    else:
        pass
count = 0
for i in b:
    count += 1
    if len(b) == count:
        print(i)
        break
    print(i, end="")
    print(" ", end="")

Submission status: Accepted

Solution code:
#! python3
# structured_programming.py

n = int(input())

for i in range(1, n+1):
    if i%3 == 0:
        print(' ' + str(i), end='')
    else:
        x = i
        while x != 0:
            if x%10 == 3:
                print(' ' + str(i), end='')
                break
            x = int(x/10)
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:
#x = [int(i) for i in input().split()]
n = int(input())
for i in range(1, n+1):
    cnt = 0
    if i % 3 == 0:
        print(" ",i,sep="",end="")
        cnt += 1
    elif cnt == 0:
        x = i
        while True:
            if x % 10 == 3:
                print(" ",i,sep="",end="")
                cnt += 1
                break
            elif x // 10 == 0:
                cnt += 1
                break
            else:
                x = x // 10
print("")

Submission status: Accepted

Solution code:
import sys
import math
 
n = input()
 
for x in xrange(1, n+1) :
    if x % 3 == 0 or str(x).find("3") != -1 :
        sys.stdout.write(" " + str(x))
print

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_correct(i):
    if i % 3 == 0: return True
    while i > 0:
        if i % 10 == 3: return True
        i = i // 10
    return False
 
def main():
    n = int(input())
    answer = ""
    for i in range(1, n + 1):
        if is_correct(i): answer += " " + str(i)
    print(answer)    
 
if __name__ == "__main__":
    main()

Submission status: Accepted

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