PS/Baekjoon Online Judge

[백준 06491] Perfection [Python]

kimyoungrok 2024. 7. 28. 13:31
728x90

문제

From the article Number Theory in the 1994 Microsoft Encarta: "If a, b, c are integers such that a = bc, a is called a multiple of b or of c, and b or c is called a divisor or factor of a. If c is not 1, b is called a proper divisor of a. Even integers, which include 0, are multiples of 2, for example, -4, 0, 2, 10; an odd integer is an integer that is not even, for example, -5, 1, 3, 9. A perfect number is a positive integer that is equal to the sum of all its positive, proper divisors; for example, 6, which equals 1 + 2 + 3, and 28, which equals 1 + 2 + 4 + 7 + 14, are perfect numbers. A positive number that is not perfect is imperfect and is deficient or abundant according to whether the sum of its positive, proper divisors is smaller or larger than the number itself. Thus, 9, with proper divisors 1, 3, is deficient; 12, with proper divisors 1, 2, 3, 4, 6, is abundant."

Problem Statement:  Given a number, determine if it is perfect, abundant, or deficient.

입력

A list of N positive integers (none greater than 60,000), with 1 < N < 100. A 0 will mark the end of the list.

출력

The N lines of output should list for each input integer whether it is perfect, deficient, or abundant, as shown in the example below.


풀이

입력받은 각 숫자와

숫자가 가지는 약수들의 합을 비교하는 문제다.

만약 합이 입력받은 수보다 작다면 'DEFICIENT' 같으면 'PERFECT', 클 경우 'ABUNDANT'를 출력하면 된다.

 

그런데 틀렸다.

찾아보니 입력이 한 줄로 들어온다는 보장이 없다.

https://www.acmicpc.net/board/view/54969

 

input을 한 줄 입력(readline) 대신 전체 입력(read)으로 변경해주자.


소스코드

보기


출처

https://www.acmicpc.net/problem/6491

728x90