Last active
November 7, 2019 05:57
-
-
Save pinglunliao/062a8a190df260754b77a0dd27b3a93a to your computer and use it in GitHub Desktop.
c032: 00382 - Perfection FYI: https://yunlinsong.blogspot.com/2015/03/c032-00382-perfection.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
msg = {0:"PERFECT", 1:"ABUNDANT", -1:"DEFICIENT"} | |
def checkPerfection(n): | |
sum = 0 | |
for i in range(1, (n // 2) + 1, 1): | |
if( n % i == 0 ): | |
sum += i | |
if( n == sum ): | |
return 0 | |
elif( n > sum ): | |
return -1 | |
elif( n < sum ): | |
return 1 | |
num = [] | |
n = 1 | |
for s in sys.stdin: | |
tn = list(map(int,s.split())) | |
for n in tn: | |
if n == 0: | |
break | |
num.append(n) | |
if n == 0: | |
break | |
print('PERFECTION OUTPUT') | |
for n in num: | |
ret = checkPerfection(n) | |
print("%5d %s" % (n, msg[ret])) | |
print('END OF OUTPUT') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment