[백준/파이썬] 16861번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 16861번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
We’re all familiar with harshad numbers. For this problem, you will … what’s that? You aren’t familiar with harshad numbers? They’re also known as Niven numbers – does that ring a bell?? Anything???
Well, it’s a simple enough concept. A harshad number is a number which is evenly divisible by the sum of its digits. For example, 24 is a harshad number: the sum of its digits is 2 + 4 = 6 and 24 is divisible by 6. 156 is also a harshad number, since 1 + 5 + 6 = 12 and 156 = (12)(13). …
입력 요약
Input consists of a single line containing a positive integer n ≤ 1 000 000 000.
출력 요약
Display the smallest harshad number greater than or equal to n.
코드
import sys;read=sys.stdin.readline
n=int(read())
while True:
if n%sum(map(int,str(n)))==0:break
n+=1
print(n)
설명
핵심은 구현 관점에서 We’re all familiar with harshad numbers. For this problem, you will … …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기