문제
풀이
- 금민수의 개수는 숫자의 자릿수에 의해 결정됨.
(ex. 2자리 수 인 경우 44, 47, 74, 77 이고 이는 2 ** 2)
- collections 모듈의 product함수를 사용하여 입력 값 범위의 모든 경우를 구함.
(✔ product : 중복순열을 구해줌)
- for문과 range 함수를 통해 a, b 사이에 몇 개의 금민수가 있는지 세어줌.
코드
from itertools import product
def solution() :
a, b = map(int, input().split())
min = len(str(a))
max = len(str(b))
factor = ["4", "7"]
res = []
for i in range(min, max + 1) :
sub = list(map(lambda x : int(''.join(x)), product(factor, repeat = i)))
for s in sub :
res.append(s)
count = 0
for r in res :
if r in range(a, b+1) :
count += 1
if r > b+1 :
break
print(count)
solution()