You are given two integers ‘X’ and ‘Y’. Your task is to find if the given integers are an amicable pair.
A pair of numbers are called Amicable if the sum of the proper divisor of each number is equal to the other number. Print ‘True’ if the numbers form amicable pair otherwise print ‘False’
A positive proper divisor is a positive divisor of a number, excluding itself. For example, 1, 2, and 3 are positive proper divisors of 6, but 6 itself is not.
For example:
Let 'X' = 220 and 'Y' = 284 form an amicable pair as the sum of the proper divisor of one is equal to the other.
The first line of the input contains ‘T’ denoting the number of test cases.
In the first line of each test case take two space-separated integers, ‘X’ and ‘Y’
Output Format:
For each test case, print a string denoting whether the pair are amicable or not, 'True' if pair are amicable else 'False'
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 20
0 <= X,Y <=10^5
Time Limit: 1 sec
2
4 8
220 284
False
True
In test case 1:
Proper divisors of 4 are 1 and 2 with sum 3!=8.
Proper divisors of 8 are 1, 2, and 4 with sum 7!=4
Thus they are not amicable pairs.
In test case 2:
Proper divisors of X=220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110.
The sum of these is 284 = Y.
Proper divisors of Y=284 are 1, 2, 4, 71, and 142.
The sum of these is 220 = X.
Thus they are amicable pairs.
3
67095 71145
253 487
280 81
True
False
False
67095 & 71145 are amicable pairs while 253 & 487 and 280 and 81 are not amicable numbers.
Try to find all proper divisor using brute force.
Approach: Here to find all the proper divisors of a number ‘N’, we will check all the numbers between 1 to N - 1 which divide N. Taking their sum we will compare it with the other number and judge whether the pair is amicable.
Algorithm:
O(X + Y), where X and Y are the numbers described in the problem
We will be traversing all the numbers between 1 to X - 1 and from 1 to Y - 1, hence the complexity.
O(1)
No additional memory will be used except for the reserved stack memory.