import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long sum = 0;
		long n;
		long num = scan.nextLong();
		for(long a = 1; a<=num; a++) {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		}System.out.println(sum);

	}

	public static long gcd(long x, long y) {
    long tmp;
    while ((tmp = x % y) != 0) {
        x = y;
        y = tmp;
    }

    return y;
}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long sum = 0;
		long n;
		long num = scan.nextLong();
		for(long a = 1; a<=num; a++) {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		}System.out.println(sum);

	}

	public static long gcd(long x, long y) {
    long tmp;
    while ((tmp = x % y) != 0) {
        x = y;
        y = tmp;
    }

    return y;
}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long sum = 0;
		long n;
		long num = scan.nextLong();
		for(long a = 1; a<=num; a++) {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		}System.out.println(sum);

	} main {
		Scanner scan = new Scanner(System.in);
		long sum = 0;
		long n;
		long num = scan.nextLong();
		for(long a = 1; a<=num; a++) {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		}System.out.println(sum);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long sum = 0; sum 0 long n; n long num = scan.nextLong(); num scan.nextLong() scan.nextLong scan for(long a = 1; a<=num; a++) {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		} long a = 1; long a = 1; a 1 a<=num a num a++ a++ a {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		} {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		} for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			} long b = 1; long b = 1; b 1 b<=num b num b++ b++ b {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			} {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			} for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				} long c = 1; long c = 1; c 1 c<=num c num c++ c++ c {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				} {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				} if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					} a>=b a b {
						n = gcd(a,b);
					} n = gcd(a,b) n gcd(a,b) gcd a b {
						n = gcd(b,a);
					} n = gcd(b,a) n gcd(b,a) gcd b a if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					} a>=c a c {
						n = gcd(n,c);
					} n = gcd(n,c) n gcd(n,c) gcd n c {
						n = gcd(c,n);
					} n = gcd(c,n) n gcd(c,n) gcd c n sum = sum+n sum sum+n sum n System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static long gcd(long x, long y) {
    long tmp;
    while ((tmp = x % y) != 0) {
        x = y;
        y = tmp;
    }

    return y;
} gcd {
    long tmp;
    while ((tmp = x % y) != 0) {
        x = y;
        y = tmp;
    }

    return y;
} long tmp; tmp while ((tmp = x % y) != 0) {
        x = y;
        y = tmp;
    } (tmp = x % y) != 0 (tmp = x % y) tmp x % y x y 0 {
        x = y;
        y = tmp;
    } x = y x y y = tmp y tmp return y; y long x x long y y public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long sum = 0;
		long n;
		long num = scan.nextLong();
		for(long a = 1; a<=num; a++) {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		}System.out.println(sum);

	}

	public static long gcd(long x, long y) {
    long tmp;
    while ((tmp = x % y) != 0) {
        x = y;
        y = tmp;
    }

    return y;
}

} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long sum = 0;
		long n;
		long num = scan.nextLong();
		for(long a = 1; a<=num; a++) {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		}System.out.println(sum);

	}

	public static long gcd(long x, long y) {
    long tmp;
    while ((tmp = x % y) != 0) {
        x = y;
        y = tmp;
    }

    return y;
}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long sum = 0;
		long n;
		long num = scan.nextLong();
		for(long a = 1; a<=num; a++) {
			for(long b = 1; b<=num; b++) {
				for(long c = 1; c<=num; c++) {
					if(a>=b) {
						n = gcd(a,b);
					}else {
						n = gcd(b,a);
					}

					if(a>=c) {
						n = gcd(n,c);
					}else {
						n = gcd(c,n);
					}

					sum = sum+n;
				}
			}
		}System.out.println(sum);

	}

	public static long gcd(long x, long y) {
    long tmp;
    while ((tmp = x % y) != 0) {
        x = y;
        y = tmp;
    }

    return y;
}

}
