#58Medium
Amicable numbers
Time: 1 s · Memory: 256 MB
- Nested loops
Statement
Two different natural numbers are called amicable if the sum of the divisors of (other than ) equals and the sum of the divisors of equals . For example, and : , .
You are given a natural number . Find all amicable pairs with both numbers not exceeding .
Input format
A single integer ().
Output format
Each pair on its own line: and (), in increasing order of . If there are no pairs — 0.
Examples
Input
300
Output
220 284
Input
100
Output
0
Note
It is convenient to move the inner loop that sums the divisors into a function: find and check that and . It is enough to check divisors up to , not up to : if is a divisor, so is . Write the condition as d * d <= x.
