easy +10 pts

Amicable Numbers Check

Determine whether a pair of integers forms an amicable pair using proper divisors.

Two distinct positive integers a and b are called an *amicable pair* if the sum of the proper divisors of a equals b and the sum of the proper divisors of b equals a. The proper divisors of a number n are all positive divisors of n excluding n itself. Implement a function `is_amicable(a, b)` that returns `True` if `a` and `b` form an amicable pair, and `False` otherwise. **Input:** Two integers `a` and `b` with `1 <= a, b <= 10^6`. **Output:** A boolean value. **Note:** The function must be deterministic and efficient enough for the given limits.

Constraints

1 <= a, b <= 10^6. The function should handle repeated calls efficiently. Time complexity for a single call: O(sqrt(max(a,b))) is acceptable.

Example

>>> is_amicable(220, 284)
True
>>> is_amicable(1184, 1210)
True
>>> is_amicable(6, 6)
False
>>> is_amicable(100, 200)
False
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

The sum of proper divisors of n equals the sum of all positive divisors minus n itself.
Iterate from 1 to sqrt(n) to find divisors, adding both divisor pairs.
Remember to exclude n itself from the sum.
First compute the sum for a and compare to b; then compute the sum for b and compare to a.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.