[백준] 1527. 금민수의 개수

원숭2·2022년 1월 15일
0

백준

목록 보기
2/54

문제

풀이

  1. 금민수의 개수는 숫자의 자릿수에 의해 결정됨.
    (ex. 2자리 수 인 경우 44, 47, 74, 77 이고 이는 2 ** 2)
  2. collections 모듈의 product함수를 사용하여 입력 값 범위의 모든 경우를 구함.
    (✔ product : 중복순열을 구해줌)
  3. 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()

0개의 댓글