1. 


/**
* ACM Problem #11417
*
* Status : accepted
* Runtime: 0.600
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 03/18/2009
*
*/

import java.util.Scanner;

class Main {

/**
* static method GCD, which calculates the gcd (greatest common devisor)
*
* @param a: An integer value, representing number a
* @param b: An integer value, representing number b
* @return gcd as an integer value
*/
public static int GCD(int a, int b){

while (a!=b){
if (a>b) a -= b;
else b -= a;
}
return a;
}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
int number, gcd;

while(sc.hasNext())
{
//reads a number from command line until a number is zero
number = sc.nextInt();
if (number==0)
break;
gcd=0;

//calculates gcd with the formula given in the problem
for(int i=1;i<number;i++)
for(int j=i+1;j<=number;j++)
{
gcd+=GCD(i,j);
}

System.out.println(gcd);
}

}

}