- [백준] 16412번: Heir’s Dilemma - 파이썬2024년 11월 28일 19시 06분 17초에 업로드 된 글입니다.작성자: B1NK728x90
- 백준 링크: 16412번: Heir’s Dilemma
- solved.ac 난이도: 브론즈 II
- 시간 제한: 2 초
- 메모리 제한: 512 MB
문제
Your favorite uncle has passed away, leaving you a large estate. Bank account numbers, locations of safe deposit boxes, and GPS coordinates to buried treasures are all locked in an electronic safe in your uncle’s office behind a picture of dogs playing poker. One day he showed you the safe with its 9 digit keypad (digits 1 through 9). He told you he wasn’t worried about anyone breaking into his safe because it’s equipped with a self-destruct mechanism that will destroy the contents if anyone attempts a forced entry.
입력
The input is a line with two space-separated integers L and H, where 123 456 ≤ L < H ≤ 987 654
출력
Print one integer, the total number of possible combinations to the safe, where each combination c must satisfy the three constraints above, and lie in the range L ≤ c ≤ H.
코드
def main(): import sys input = sys.stdin.read data = input().strip().split() a = int(data[0]) b = int(data[1]) ans = 0 for i in range(a, b + 1): tmp = i cnt = [0] * 10 while tmp > 0: cnt[tmp % 10] += 1 tmp //= 10 check = True for j in range(10): if cnt[j] >= 2: check = False if cnt[0] >= 1: check = False if not check: continue for j in range(1, 10): if cnt[j] == 0: continue if i % j != 0: check = False if check: ans += 1 print(ans) if __name__ == "__main__": main()
728x90'백준' 카테고리의 다른 글
[백준] 18691번: Pokemon Buddy - 파이썬 (0) 2024.11.27 [백준] 12865번: 평범한 배낭 - 파이썬 (0) 2024.11.26 [백준] 2303번: 숫자 게임 - 파이썬 (0) 2024.11.25 [백준] 30502번: 미역은 식물 아닌데요 - 파이썬 (0) 2024.11.24 [백준] 1296번: 팀 이름 정하기 - 파이썬 (0) 2024.11.23 다음글이 없습니다.이전글이 없습니다.댓글