import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int K = input.nextInt();
		long sum = 0;
		for (int i = 1; i <= K; i++) {
			sum+=i;
		}
		for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		}
		System.out.println(sum);
	}
	public static long GCD(int a, int b, int c) {
		long max = 1;
		int min = Math.min(Math.min(a, b),c);
		for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} 
		return max;
	}
	public static boolean Prime(int n) {
		for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		}
		return true;
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int K = input.nextInt();
		long sum = 0;
		for (int i = 1; i <= K; i++) {
			sum+=i;
		}
		for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		}
		System.out.println(sum);
	}
	public static long GCD(int a, int b, int c) {
		long max = 1;
		int min = Math.min(Math.min(a, b),c);
		for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} 
		return max;
	}
	public static boolean Prime(int n) {
		for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		}
		return true;
	}
} Main public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int K = input.nextInt();
		long sum = 0;
		for (int i = 1; i <= K; i++) {
			sum+=i;
		}
		for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		}
		System.out.println(sum);
	} main {
		Scanner input = new Scanner(System.in);
		int K = input.nextInt();
		long sum = 0;
		for (int i = 1; i <= K; i++) {
			sum+=i;
		}
		for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		}
		System.out.println(sum);
	} Scanner input = new Scanner(System.in); input new Scanner(System.in) int K = input.nextInt(); K input.nextInt() input.nextInt input long sum = 0; sum 0 for (int i = 1; i <= K; i++) {
			sum+=i;
		} int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
			sum+=i;
		} {
			sum+=i;
		} sum+=i sum i for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		} int a = 1; int a = 1; a 1 a <= K a K a++ a++ a {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		} {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		} for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			} int b = a+1; int b = a+1; b a+1 a 1 b <= K&& b!=a b <= K b K b!=a b a b++ b++ b {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			} {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			} sum+=GCD(a,b,b)*3 sum GCD(a,b,b)*3 GCD(a,b,b) GCD a b b 3 sum+=GCD(a,a,b)*3 sum GCD(a,a,b)*3 GCD(a,a,b) GCD a a b 3 for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} int c = b+1; int c = b+1; c b+1 b 1 c <= K && c!=a&&c!=b c <= K && c!=a&&c!=b c <= K c K c!=a c a c!=b c b c++ c++ c {
					sum+=GCD(a,b,c)*6;
				} {
					sum+=GCD(a,b,c)*6;
				} sum+=GCD(a,b,c)*6 sum GCD(a,b,c)*6 GCD(a,b,c) GCD a b c 6 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static long GCD(int a, int b, int c) {
		long max = 1;
		int min = Math.min(Math.min(a, b),c);
		for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} 
		return max;
	} GCD {
		long max = 1;
		int min = Math.min(Math.min(a, b),c);
		for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} 
		return max;
	} long max = 1; max 1 int min = Math.min(Math.min(a, b),c); min Math.min(Math.min(a, b),c) Math.min Math Math.min(a, b) Math.min Math a b c for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} long i = 2; long i = 2; i 2 i <= min i min i++ i++ i {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} if (a%i==0&&b%i==0&&c%i==0) max=i; a%i==0&&b%i==0&&c%i==0 a%i==0&&b%i==0&&c%i==0 a%i==0 a%i a i 0 b%i==0 b%i b i 0 c%i==0 c%i c i 0 max=i max i return max; max int a a int b b int c c public static boolean Prime(int n) {
		for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		}
		return true;
	} Prime {
		for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		}
		return true;
	} for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		} int i = 2; int i = 2; i 2 i <= Math.sqrt(n) i Math.sqrt(n) Math.sqrt Math n i++ i++ i {
			if (n%i==0) return false;
		} {
			if (n%i==0) return false;
		} if (n%i==0) return false; n%i==0 n%i n i 0 return false; false return true; true int n n public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int K = input.nextInt();
		long sum = 0;
		for (int i = 1; i <= K; i++) {
			sum+=i;
		}
		for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		}
		System.out.println(sum);
	}
	public static long GCD(int a, int b, int c) {
		long max = 1;
		int min = Math.min(Math.min(a, b),c);
		for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} 
		return max;
	}
	public static boolean Prime(int n) {
		for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		}
		return true;
	}
} public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int K = input.nextInt();
		long sum = 0;
		for (int i = 1; i <= K; i++) {
			sum+=i;
		}
		for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		}
		System.out.println(sum);
	}
	public static long GCD(int a, int b, int c) {
		long max = 1;
		int min = Math.min(Math.min(a, b),c);
		for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} 
		return max;
	}
	public static boolean Prime(int n) {
		for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		}
		return true;
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int K = input.nextInt();
		long sum = 0;
		for (int i = 1; i <= K; i++) {
			sum+=i;
		}
		for (int a = 1; a <= K; a++) {
			for (int b = a+1; b <= K&& b!=a; b++) {
				sum+=GCD(a,b,b)*3;
				sum+=GCD(a,a,b)*3;
				for (int c = b+1; c <= K && c!=a&&c!=b; c++){
					sum+=GCD(a,b,c)*6;
				} 
			}
		}
		System.out.println(sum);
	}
	public static long GCD(int a, int b, int c) {
		long max = 1;
		int min = Math.min(Math.min(a, b),c);
		for (long i = 2; i <= min; i++) {
			if (a%i==0&&b%i==0&&c%i==0) max=i;
		} 
		return max;
	}
	public static boolean Prime(int n) {
		for (int i = 2; i <= Math.sqrt(n); i++) {
			if (n%i==0) return false;
		}
		return true;
	}
}