1.

/**
* Angewandte Mathematik, SS11
* Problem: 11417 GCD
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=23&page=show_problem&problem=11417
*
* @author Peter Weismann
* @author Pirmin Schneider
* @version 1.0, 05/03/2011
*
* Method : Ad-Hoc
* Status : Accepted
* Runtime: 0.396
*/
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int value = input.nextInt();
int G = 0;

while (value != 0) {
G = 0;

for(int i = 1; i < value; i++) {
for(int j = i+1 ; j <= value; j++) {
G += ggT(i,j);
}
}
System.out.println(G);
value = input.nextInt();
}
}

// Zusätzliche Methode prüft, ob ggT 1 ist
public static int ggT(int a, int b) {
while (a != b) {
if (a>b)
a = a-b;
else
b = b-a;
}
return a;
}

}



-----------------------------------------------------------------------------------

1.

/**
* FWP, Ausgewhlte Probleme aus dem ACM Programming Contest, SS10
* Problem: 11417 GCD
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=26&page=show_problem&problem=2412
*
* @author Reichart Robert
* @version 1.0
*
* Status : Accepted
* Runtime: 0.400
*/

import java.io.*;

class Main{
public static void main(String... args)throws Exception{
//try{
//Scanner in = new Scanner(System.in);
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line=in.readLine();
while (!line.equals("0")){

if (!line.equals("")){

int tmp=Integer.parseInt(line.trim());

int sum=0;
if (tmp!=0){
for (int i=1;i<tmp;i++){
for (int j=i+1;j<=tmp;j++){
sum+=ggt(i,j);
}
}
}
System.out.println(sum);
}
line=in.readLine();

}

}

private static int ggt(int zahl1, int zahl2) {
while (zahl2 != 0) {
if (zahl1 > zahl2) {
zahl1 = zahl1 - zahl2;
} else {
zahl2 = zahl2 - zahl1;
}
}
return zahl1;
}
}