220 and 284 is called amicable because the sum of the proper divisors of one is equal to the other.
1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284
1 + 2 + 4 + 71 + 142 = 220
For fun and there’s no reason we can’t do this. if including the negative number, will find:
1 + (-1) + 2 + (-2) + 4 + (-4) + 71 + (-71) + 142 + (-142) + 284 = 284
Isn’t it perfect?
#!/usr/bin/env python
import pandas as pd
import itertools
class Factorization:
def __init__(self, input, plist):
self.input = input
self.input_cp = input
self.plist = plist
def prime_facterise(self):
pflist = []
used_plist = []
dupli_plist = []
if self.input <= self.plist[-1]:
for p in self.plist:
while self.input % p == 0:
if p not in used_plist:
used_plist.append(p)
else:
dupli_plist.append(p)
self.input = self.input / p
for i in used_plist:
if i not in pflist:
pflist.append(i)
allpf = pflist + dupli_plist
if self.input_cp < 0:
allpf += [(-1) * i for i in allpf]
allpf.append(-1)
pflist += [(-1) * i for i in pflist]
pflist.append(-1)
allpf.append(1)
pflist.append(1)
return allpf, pflist, dupli_plist
def facterise(self):
allpf = self.prime_facterise()[0]
allf = []
uflist = []
for i in range(1, len(allpf) + 1):
iter = itertools.combinations(allpf, i)
allf.append(list(iter))
f = 1
flist = []
if allf != []:
for l in allf:
for t in l:
for i in t:
f *= i
flist.append(f)
f = 1
for f in flist:
if self.input_cp % f == 0:
uflist.append(f)
uflist = list(set(uflist))
return uflist
df = pd.read_csv('./prime1000.csv')
plist = df['prime'].tolist()
# example
f = Factorization(220, plist)
factors = f.factorize()