import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long sum = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		}
		System.out.println(sum);
	}
	private static long solve(long i, long j, long n) {
		long tmp;
		long a = i;
		long b = j;
		long gcd;
		while((tmp = b % a) != 0) {
			b=a;
			a=tmp;
		}
		gcd = a;
		long c;
		if(n<gcd) {
			a = n;
			c = gcd;
		}
		else {
			a = gcd;
			c = n;
		}
		while((tmp = c % a) != 0) {
			c=a;
			a=tmp;
		}
		//System.out.println(a);
		return a;
	}
} import java.util.*; util.* java import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue; Queue java.util import java.math.RoundingMode; RoundingMode java.math import java.math.BigDecimal; BigDecimal java.math public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long sum = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		}
		System.out.println(sum);
	}
	private static long solve(long i, long j, long n) {
		long tmp;
		long a = i;
		long b = j;
		long gcd;
		while((tmp = b % a) != 0) {
			b=a;
			a=tmp;
		}
		gcd = a;
		long c;
		if(n<gcd) {
			a = n;
			c = gcd;
		}
		else {
			a = gcd;
			c = n;
		}
		while((tmp = c % a) != 0) {
			c=a;
			a=tmp;
		}
		//System.out.println(a);
		return a;
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long sum = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		}
		System.out.println(sum);
	} main {
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long sum = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		}
		System.out.println(sum);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long k = sc.nextLong(); k sc.nextLong() sc.nextLong sc long sum = 0; sum 0 for(int i = 1; i <= k; i++) {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		} int i = 1; int i = 1; i 1 i <= k i k i++ i++ i {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		} {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		} for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			} int j = i; int j = i; j i j <= k j k j++ j++ j {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			} {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			} for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				} int n = j; int n = j; n j n <= k n k n++ n++ n {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				} {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				} if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					} i==j&&j==n i==j i j j==n j n {
						sum+=solve(i,j,n);
					} sum+=solve(i,j,n) sum solve(i,j,n) solve i j n if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					} i!=j&&j!=n&&n!=i i!=j&&j!=n&&n!=i i!=j i j j!=n j n n!=i n i {
						sum+=solve(i,j,n)*6;
					} sum+=solve(i,j,n)*6 sum solve(i,j,n)*6 solve(i,j,n) solve i j n 6 {
						sum+=solve(i,j,n)*3;
					} sum+=solve(i,j,n)*3 sum solve(i,j,n)*3 solve(i,j,n) solve i j n 3 System.out.println(sum) System.out.println System.out System System.out sum String[] args args private static long solve(long i, long j, long n) {
		long tmp;
		long a = i;
		long b = j;
		long gcd;
		while((tmp = b % a) != 0) {
			b=a;
			a=tmp;
		}
		gcd = a;
		long c;
		if(n<gcd) {
			a = n;
			c = gcd;
		}
		else {
			a = gcd;
			c = n;
		}
		while((tmp = c % a) != 0) {
			c=a;
			a=tmp;
		}
		//System.out.println(a);
		return a;
	} solve {
		long tmp;
		long a = i;
		long b = j;
		long gcd;
		while((tmp = b % a) != 0) {
			b=a;
			a=tmp;
		}
		gcd = a;
		long c;
		if(n<gcd) {
			a = n;
			c = gcd;
		}
		else {
			a = gcd;
			c = n;
		}
		while((tmp = c % a) != 0) {
			c=a;
			a=tmp;
		}
		//System.out.println(a);
		return a;
	} long tmp; tmp long a = i; a i long b = j; b j long gcd; gcd while((tmp = b % a) != 0) {
			b=a;
			a=tmp;
		} (tmp = b % a) != 0 (tmp = b % a) tmp b % a b a 0 {
			b=a;
			a=tmp;
		} b=a b a a=tmp a tmp gcd = a gcd a long c; c if(n<gcd) {
			a = n;
			c = gcd;
		}
		else {
			a = gcd;
			c = n;
		} n<gcd n gcd {
			a = n;
			c = gcd;
		} a = n a n c = gcd c gcd {
			a = gcd;
			c = n;
		} a = gcd a gcd c = n c n while((tmp = c % a) != 0) {
			c=a;
			a=tmp;
		} (tmp = c % a) != 0 (tmp = c % a) tmp c % a c a 0 {
			c=a;
			a=tmp;
		} c=a c a a=tmp a tmp return a; a long i i long j j long n n public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long sum = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		}
		System.out.println(sum);
	}
	private static long solve(long i, long j, long n) {
		long tmp;
		long a = i;
		long b = j;
		long gcd;
		while((tmp = b % a) != 0) {
			b=a;
			a=tmp;
		}
		gcd = a;
		long c;
		if(n<gcd) {
			a = n;
			c = gcd;
		}
		else {
			a = gcd;
			c = n;
		}
		while((tmp = c % a) != 0) {
			c=a;
			a=tmp;
		}
		//System.out.println(a);
		return a;
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long sum = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		}
		System.out.println(sum);
	}
	private static long solve(long i, long j, long n) {
		long tmp;
		long a = i;
		long b = j;
		long gcd;
		while((tmp = b % a) != 0) {
			b=a;
			a=tmp;
		}
		gcd = a;
		long c;
		if(n<gcd) {
			a = n;
			c = gcd;
		}
		else {
			a = gcd;
			c = n;
		}
		while((tmp = c % a) != 0) {
			c=a;
			a=tmp;
		}
		//System.out.println(a);
		return a;
	}
} Main
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long k = sc.nextLong();
		long sum = 0;
		for(int i = 1; i <= k; i++) {
			for(int j = i; j <= k; j++) {
				for(int n = j; n <= k; n++) {
					//System.out.println("Debug");
					if(i==j&&j==n) {
						sum+=solve(i,j,n);
					}
					else if(i!=j&&j!=n&&n!=i) {
						sum+=solve(i,j,n)*6;
					}
					else{
						sum+=solve(i,j,n)*3;
					}
				}
			}
		}
		System.out.println(sum);
	}
	private static long solve(long i, long j, long n) {
		long tmp;
		long a = i;
		long b = j;
		long gcd;
		while((tmp = b % a) != 0) {
			b=a;
			a=tmp;
		}
		gcd = a;
		long c;
		if(n<gcd) {
			a = n;
			c = gcd;
		}
		else {
			a = gcd;
			c = n;
		}
		while((tmp = c % a) != 0) {
			c=a;
			a=tmp;
		}
		//System.out.println(a);
		return a;
	}
}