Last active
March 16, 2025 17:34
-
-
Save orjanv/ada571000058406337b82ac9efeae943 to your computer and use it in GitHub Desktop.
Find romantic (amicable) numbers
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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
def get_divisors(n): | |
divisors = [] | |
for i in range(1, int(n / 2) + 1): | |
if n % i == 0: | |
divisors.append(i) | |
return divisors | |
if __name__ == "__main__": | |
romantic_numbers = [] | |
for n in range(10, 100000 + 1): | |
n1 = sum(get_divisors(n)) | |
n2 = sum(get_divisors(n1)) | |
if n == n2 and n != n1: | |
romantic_numbers.append(n) | |
if n1 not in romantic_numbers: | |
print(f'{n} and {n1}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment