import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int sum = 0;

		for(int i =1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		}

		System.out.println(sum);
		scan.close();
	}

	public static int Euqlid(int a,int b){

		if(b == 0) {
			return a;
		}else

		return Euqlid(b,a%b);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int sum = 0;

		for(int i =1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		}

		System.out.println(sum);
		scan.close();
	}

	public static int Euqlid(int a,int b){

		if(b == 0) {
			return a;
		}else

		return Euqlid(b,a%b);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int sum = 0;

		for(int i =1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		}

		System.out.println(sum);
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int sum = 0;

		for(int i =1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		}

		System.out.println(sum);
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int k = scan.nextInt(); k scan.nextInt() scan.nextInt scan int sum = 0; sum 0 for(int i =1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		} int i =1; int i =1; i 1 i<=k i k i++ i++ i {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		} {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		} for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			} int j=1; int j=1; j 1 j<=k j k j++ j++ j {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			} {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			} for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				} int l=1; int l=1; l 1 l<=k l k l++ l++ l {

			sum += Euqlid(i,Euqlid(j,l));
				} {

			sum += Euqlid(i,Euqlid(j,l));
				} sum += Euqlid(i,Euqlid(j,l)) sum Euqlid(i,Euqlid(j,l)) Euqlid i Euqlid(j,l) Euqlid j l System.out.println(sum) System.out.println System.out System System.out sum scan.close() scan.close scan String[] args args public static int Euqlid(int a,int b){

		if(b == 0) {
			return a;
		}else

		return Euqlid(b,a%b);
	} Euqlid {

		if(b == 0) {
			return a;
		}else

		return Euqlid(b,a%b);
	} if(b == 0) {
			return a;
		}else

		return Euqlid(b,a%b); b == 0 b 0 {
			return a;
		} return a; a return Euqlid(b,a%b); Euqlid(b,a%b) Euqlid b a%b a b int a a int b b public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int sum = 0;

		for(int i =1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		}

		System.out.println(sum);
		scan.close();
	}

	public static int Euqlid(int a,int b){

		if(b == 0) {
			return a;
		}else

		return Euqlid(b,a%b);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int sum = 0;

		for(int i =1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		}

		System.out.println(sum);
		scan.close();
	}

	public static int Euqlid(int a,int b){

		if(b == 0) {
			return a;
		}else

		return Euqlid(b,a%b);
	}
} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int k = scan.nextInt();
		int sum = 0;

		for(int i =1;i<=k;i++) {
			for(int j=1;j<=k;j++) {
				for(int l=1;l<=k;l++) {

			sum += Euqlid(i,Euqlid(j,l));
				}
			}
		}

		System.out.println(sum);
		scan.close();
	}

	public static int Euqlid(int a,int b){

		if(b == 0) {
			return a;
		}else

		return Euqlid(b,a%b);
	}
}
