Created
April 18, 2020 23:27
-
-
Save lilpolymath/3041b4323474ac75df8703a0b1561875 to your computer and use it in GitHub Desktop.
Perfect Number
This file contains hidden or 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
def solve(number): | |
sum = 0 | |
middle = int(number/2) + 1 | |
for i in range(1,middle): | |
if number%i == 0: | |
sum += i | |
if sum == number: | |
return sum | |
if __name__ == "__main__": | |
rangeTo = int(input()) | |
perfect = [] | |
for i in range(rangeTo + 1): | |
number = solve(i) | |
if number: | |
perfect.append(number) | |
print(perfect) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It has an issue with 0 because of the long long int type.