August 06, 2018

220 and 284

A short note on an amicable pair and why negative numbers do not belong in it.

An amicable pair

220 and 284 is called amicable because the sum of the proper divisors of one is equal to the other.

  • 220: 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, 220

1 + 2 + 4 + 5 + 10 + 11 + 20 + 22 + 44 + 55 + 110 = 284

  • 284: 1, 2, 4, 71, 142, 284

1 + 2 + 4 + 71 + 142 = 220

Why not include the negative number

For fun and there’s no reason we can’t do this. if including the negative number, will find:

The sum of the divisors of each negative number is its opposite

  • 284: 1, -1, 2, -2, 4, -4, 71, -71, 142, -142, 284, -284

1 + (-1) + 2 + (-2) + 4 + (-4) + 71 + (-71) + 142 + (-142) + 284 = 284

Isn’t it perfect?

More positive numbers could get their amicable friends

  • 1, -1
  • 3, -2
  • 4, -3
  • 7, -4
  • 6, -5
  • 12, -6
  • 8, -7
  • 15, -8
  • 13, -9
  • 18, -10
  • 12, -11

Some numbers can be with 2 friends

  • 12, with -6 and -11

…a new world to explore

A method for factorization

  • get the prime factors first
  • then, combine the prime factors
  • then, get the factors which is divisible to the input
#!/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()