Two different positive integers a and b form an amicable pair when each equals the other’s proper-divisor sum (aliquot sum), written s(n).
Remember
s(n) = sum of proper divisors of n
a ≠ b
s(a) = b and s(b) = a → amicable pair
Proper divisors = positive divisors of n, except n itself
Example: s(220) = 284, s(284) = 220 → amicable
Concept
Condition
Example
Amicable pair
s(a)=b, s(b)=a, a≠b
220 & 284
Perfect
s(n) = n
6, 28
Abundant
s(n) > n
12 (not a pair)
Well-known amicable pairs
Golden tests for interviews and unit checks — start with 220 and 284.
Four clear steps — share one proper-divisor helper for both numbers.
Reject if a < 2, b < 2, or a == b.
Compute s(a) and s(b) (sum proper divisors).
Require s(a) == bands(b) == a.
Optionally print both sums so the two-way link is visible.
Method
Idea
Time
Best for
Basic loop
Sum divisors from 1 to n / 2
O(a + b)
Interviews, small values
Divisor pairs
Loop to √n; add i and n / i (skip n)
O(√a + √b)
Larger inputs, optimizations
Pseudocode
Pseudocode
function SumProperDivisors(n):
if n <= 1:
return 0
sum = 0
for i from 1 to floor(n / 2):
if n mod i == 0:
sum = sum + i
return sum
function AreAmicable(a, b):
if a < 2 or b < 2 or a == b:
return false
return SumProperDivisors(a) == b and SumProperDivisors(b) == a
Try it
Live Preview
Enter two positive integers to see s(a), s(b), and the amicable verdict.
Whole numbers ≥ 1 (capped at 999999). Order does not matter for a valid pair.
Result
a = 220, b = 284
s(220) = 284
s(284) = 220
a ≠ b: true
s(a) == b: true
s(b) == a: true
Verdict: AMICABLE PAIR
Trace
Worked Walkthrough — 220 & 284
Add the proper divisors of each number, then check both directions.
Start with the readable O(a + b) solution. Then use divisor pairs for an O(√a + √b) optimization.
Example 1 — Check One Pair
Shared SumProperDivisors helper, then the two-way amicable test.
C#
using System;
class Program
{
static int SumProperDivisors(int n)
{
if (n <= 1)
{
return 0;
}
int sum = 0;
for (int i = 1; i <= n / 2; i++)
{
if (n % i == 0)
{
sum += i;
}
}
return sum;
}
static bool AreAmicable(int a, int b)
{
if (a < 2 || b < 2 || a == b)
{
return false;
}
return SumProperDivisors(a) == b && SumProperDivisors(b) == a;
}
static void Main()
{
int a = 220;
int b = 284;
if (AreAmicable(a, b))
{
Console.WriteLine(a + " and " + b + " are amicable numbers.");
}
else
{
Console.WriteLine(a + " and " + b + " are not amicable numbers.");
}
}
}
Output
220 and 284 are amicable numbers.
How it works: sum the proper divisors of both numbers. Return true only when the sums point to each other and the inputs are different.
Example 2 — O(√n) with Divisor Pairs
Same amicable test; faster sum using divisor pairs up to √n.
C#
using System;
class Program
{
static int SumProperDivisorsFast(int n)
{
if (n <= 1)
{
return 0;
}
int sum = 1; // 1 is always a proper divisor for n > 1
for (int i = 2; i <= n / i; i++)
{
if (n % i == 0)
{
sum += i;
int partner = n / i;
if (partner != i && partner != n)
{
sum += partner;
}
}
}
return sum;
}
static bool AreAmicableFast(int a, int b)
{
if (a < 2 || b < 2 || a == b)
{
return false;
}
return SumProperDivisorsFast(a) == b
&& SumProperDivisorsFast(b) == a;
}
static void Main()
{
Console.WriteLine(AreAmicableFast(220, 284)); // True
Console.WriteLine(AreAmicableFast(1184, 1210)); // True
Console.WriteLine(AreAmicableFast(6, 6)); // False (perfect)
}
}
Output
True
True
False
How it works: each divisor i has a partner n / i. Add both once and stop at √n. Using i <= n / i avoids integer overflow.
Edge Cases & Pitfalls
Check these before calling the solution done.
a == b
Not a pair
Equal inputs are never amicable — that path is for perfect numbers.
One way
Check both
s(a) == b alone is not enough; also require s(b) == a.
Include n?
Never add n
Including n in the sum breaks every amicable and perfect check.
Squares
No double-count
In pair mode, add the square root only once when i * i == n.
Analysis
Time and Space Complexity
Program
Time
Extra space
Basic loops to n/2
O(a + b)
O(1)
Divisor pairs up to √n
O(√a + √b)
O(1)
Remember
Key Takeaways
Definition:s(a)=b, s(b)=a, and a≠b.
Helper first: one proper-divisor sum function powers the whole solution.
One line: compute both proper-divisor sums; if each equals the other number and they differ, the pair is amicable.
Frequently Asked Questions
Two different positive integers are amicable when each number equals the sum of the other number's proper divisors. The smallest pair is 220 and 284.
Create a helper that sums proper divisors. The pair is amicable when s(a) equals b, s(b) equals a, and a does not equal b.
If a number equals its own proper-divisor sum, it is a perfect number. An amicable pair must contain two different numbers.
Amicable compares two numbers whose proper-divisor sums point to each other. Abundant checks one number whose proper-divisor sum is greater than itself.
The basic method is O(a + b). The divisor-pair method is O(√a + √b). Both use O(1) extra space.