Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 7, 2019 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinglunliao/062a8a190df260754b77a0dd27b3a93a to your computer and use it in GitHub Desktop.
Save pinglunliao/062a8a190df260754b77a0dd27b3a93a to your computer and use it in GitHub Desktop.
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