Skip to content

Instantly share code, notes, and snippets.

@orjanv
Last active March 16, 2025 17:34
Show Gist options
  • Save orjanv/ada571000058406337b82ac9efeae943 to your computer and use it in GitHub Desktop.
Save orjanv/ada571000058406337b82ac9efeae943 to your computer and use it in GitHub Desktop.
Find romantic (amicable) numbers
#!/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