FRNDAM - Friendship
Mathematician Ramanujan didn’t have any close friends. Someone asked him the reason. He replied that although he wanted to have close friends but nobody was up to his expectation. When pressed how he expected his friends to be, he replied like numbers 220 and 284. The person got confused and asked what the connection between friendship and these numbers is !
Ramanujan asked him to find the divisors of each number! With much difficulty the person derived and listed them.
- 220 : 1, 2, 4, 5, 10, 11, 20, 22, 44, 55, 110, 220
- 284 : 1, 2, 4, 71, 142, 284
Ramanujan then asked the person to exclude the numbers 220 and 284 and asked the sum of the remaining divisors. The person was astonished to find:
- 220 - 1+2+4+5+10+11+20+22+44+55+110 = 284
- 284 - 1+2+4+71+142 = 220
Ramanujan explained that an ideal friendship should be like these numbers to complement each other even when one is absent the other should represent the friend !
As you’re a talented programmer you should be able to find ideal friendship between two numbers.
The first line of input will contain a positive integer T (T <= 50), denoting the number of test cases.
In each test case, there will be two integer X and Y (10 < X, Y <= 10^6)
If ideal friendship exists between two numbers then print "Friendship is ideal", if not print "Friendship is not ideal".
3 220 284 486 594 1184 1210
Friendship is ideal Friendship is not ideal Friendship is ideal
tutorial stuff, either increase number of test cases to 10^5, to avoid naive solution
AC in one go!!