728x90
시간 초과가 계속 나서 product 를 이용하는 것 까지 맞았는데, repeat = ? 를 안해주었다. 이를 잘 해주니 풀렸다.
import sys
import math
from itertools import product
a,b = map(int,input().split(" "))
answer = 0
"""
def check(num):
n = list(str(num))
for i in range(0,len(n)):
if n[i] == "4" or n[i]=="7":
continue
else:
return False
return True
for i in range(a,b+1):
if str(i)[0]=='4' or str(i)[0]=='7':
if len(str(i))>=2:
if str(i)[1]=='4' or str(i)[1]=='7':
if check(i)==True:
answer+=1
else:
if check(i)==True:
answer+=1
else:
continue
"""
temp = [ ]
count=0
for i in range(len(str(a)),len(str(b))+1):
k = list(product(['4','7'],repeat = i))
for i in range(0,len(k)):
if a<=int("".join(k[i]))<=b:
count+=1
print(count)
728x90
'🟢 알고리즘 문제 풀이 > Baekjoon' 카테고리의 다른 글
| [파이썬] 백준 15686 치킨 배달 (0) | 2023.04.07 |
|---|---|
| [파이썬] 백준 17610 양팔 저울 (0) | 2023.04.04 |
| [파이썬] 백준 2824 최대공약수 (0) | 2023.03.29 |
| [파이썬] 백준 2502 떡 먹는 호랑이 (0) | 2023.03.29 |
| [파이썬] 백준 2564 경비원 (0) | 2023.03.25 |