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

+ Recent posts