
// Amicable.java
// Andrew Davison, ad@coe.psu.ac.th, April 2023

/* Print all the Amicable number pairs between 1 and MAX_VAL.
   In 1-3000 there are three:
          (220,284), (1184,1210), (2620,2924)

   Amicable pairs are two numbers whose sum of
   their proper divisors are equal to the other number. 
   (A proper divisor is a factor other than the number
   itself. For example, the proper divisors of 6 are 
   1, 2, and 3.) 
  
   https://en.wikipedia.org/wiki/Amicable_numbers
  
   Example : (220,284) 
   220 is divisible by {1,2,4,5,10,11,20,22,44,55,110 } 
   Sum = 284

   284 is divisible by {1,2,4,71,142}
   Sum = 220

   Usage:
     > compile Amicable.java
     > run Amicable
*/


public class Amicable
{
  private static final int MAX_VAL = 3000;

  public static void main(String[] args)
  {
    int count = 0;
    System.out.println("Checking 1 to " + MAX_VAL);

    for (int i = 1; i < MAX_VAL; i++) {
      for (int j = i + 1; j <= MAX_VAL; j++) {
        // avoid checking (i,j) and (j,i)
        if (Nut.areAmicable(i, j)) {
          count++;
          System.out.println(" " + count + ". (" + i + ", " + j + ")");
        }
      }
    }
  } /* main */

}  // end of Amicable class
