Can this algorithm for testing amicable numbers return false positives?

59 Views Asked by At

I have made the following algorithm for testing if two positive integers are amicable, and I was wondering if it could return any false positives, and if so, under what conditions will it return false positives?

The algorithm is as follows:

Let's say that we are testing if $a$ and $b$ are amicable numbers. Let $m=\max(a,b)$ and $s=0$.

Looping from $i=1$ to $m-1$ inclusive, add $i$ to $s$ if $a\pmod i=0$. Then, subtract $i$ from $s$ if $b\pmod i=0$.

If $|s|=m$, then $a$ and $b$ are amicable numbers. Otherwise, they are not.

I know that if $a$ and $b$ are amicable numbers, then it is guaranteed that $|s|=m$. Here's why:

Let $A(n)$ be the aliquot sum of $n$. Assume that $m=b$. Then the loop will go from $i=1$ to $b-1$ inclusive.

After the loop ends, from the $b\pmod i$ condition, a total of $A(b)$ will be subtracted from $s$, and from the $a\pmod i$ condition, a total of $A(a)+a$ will be added to $s$. Because $A(a)=b$ and $A(b)=a$ (by definition of amicable numbers), we have that $s=A(a)+a-A(b)=b+a-a=b$, which means $|s|=b=m$.

Similarly, if $m=a$, then after the loop ends, we have that $s=A(a)-A(b)-b=b-a-b=-a$, which means $|s|=a=m$.

Taking its contrapositive, we can say that: If $|s|\ne m$, then $a$ and $b$ are guaranteed not to be amicable numbers. So it is guaranteed that there are no false negatives.

But I was wondering: What can we say if $|s|=m$? Is it possible that there are any false positives?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, it's possible to have false positives. This will occur with integers $a$ and $b$ if there's a non-zero integer $c$ where $A(a) = b + c$ and $A(b) = a + c$, since then your first case becomes

$$s = A(a) + a - A(b) = (b + c) + a - (a + c) = b$$

and your second case results in

$$s = A(a) - A(b) - b = (b + c) - (a + c) - b = -a$$

A particular situation is with $c = 1$, with these $a$ and $b$ being called betrothed numbers (also called quasi-amicable numbers). The linked Wikipedia article states the first few pairs of these numbers (e.g., $(48,75)$ and $(140,195)$), and includes a link to the associated OEIS sequence A005276.