브루트포스 문제.
파이썬 itertools 라이브러리의 product 클래스를 사용하면 문자들의 조합을 모두 뽑아낼 수 있다.
10억 이하의 4와 7로 이루어진 수의 개수는 2^9+2^8+2^7+...이므로 브루트포스로 풀어도 안정권에 든다.
모든 수를 찾아보며 A와 B 사이에 있는 지를 판단해주면 되는 문제.
product 클래스를 사용하지 않으려면 DFS나 BFS로 하나하나 확인해줘도 될 것이다.
코드는 다음과 같다.
# -*- coding: utf-8 -*-
import sys
from collections import deque
import heapq
import bisect
import math
from itertools import product
"""
from itertools import combinations
from itertools import combinations_with_replacement
from itertools import permutations
import copy
"""
#input=sys.stdin.readline
#print=sys.stdout.write
#sys.setrecursionlimit(100000000)
a,b=map(int,input().split())
ans=0
for k in range(1,10):
for i in product('47',repeat=k):
if a<=int(''.join(i))<=b:
ans+=1
print(ans)
금민수야 고맙다~
'BOJ' 카테고리의 다른 글
백준(BOJ) 10253 헨리(Python) (0) | 2023.01.11 |
---|---|
백준(BOJ) 3078 좋은 친구(Python) (0) | 2023.01.07 |
백준(BOJ) 25498 핸들 뭘로 하지(Python) (0) | 2022.08.23 |
백준(BOJ) 16236 아기 상어(Python) (0) | 2022.08.16 |
백준(BOJ) 1424 새 앨범(Python) (0) | 2022.08.10 |