UVA11417




Sample Input                              
10
100
500
0

Output for Sample Input
67
13015
442011



import java.util.Scanner;

public class UVA11417 {

 public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);

  while (sc.hasNext()) {

   int N = sc.nextInt();

   if (N == 0)
    break;

   int G = 0;

   for (int i = 1; i < N; i++)
    for (int j = i + 1; j <= N; j++) {
     G += GCD(i, j);
    }

   System.out.println(G);
  }

  sc.close();

 }

 private static int GCD(int i, int j) {

  int temp = 0;

  while (i % j != 0) {

   temp = i % j;
   i = j;
   j = temp;

  }

  return j;
 }

}