[백준/파이썬] 13225번 풀이
업데이트:
문제 정보
- 문제 출처: 백준 온라인 저지
- 문제 링크: 13225번 문제
- 문제풀이 코드 GitHub 링크
- 제출 언어: Python 3
풀이
문제
Given an integer n, compute the number of divisors of n.
A divisor is an integer, d (1 <= d <= n) that evenly divides n.
Example: If n=10, divisors are: 1, 2, 5 and 10. So the result would be 4.
Example: If n=104717, divisors are 1 and 104717. This is a prime number so the number of divisors is 2.
입력 요약
The first line contains an integer C (1 <= C <= 10) with the amount of numbers you need to process. The next C lines will contain an integer n (1 <= n < 10000) each. You have to compute the number of divisors of these values.
출력 요약
For each integer n, print a line with the number n itself, a space and the number of divisors.
코드
for T in range(int(input())):
n=int(input())
r=set()
for i in range(1,int(n**.5)+1):
if n%i==0:
r.add(i)
r.add(n//i)
print(n, len(r))
설명
핵심은 구현 관점에서 Given an integer n, compute the number of divisors of n.
A divisor is an integer, d (1 <= d <= n) that evenly divides n. …를 만족하도록 로직을 구성하는 것입니다.
코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.
경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.
댓글남기기