import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;
		int gcd = 1;
	    for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    }
	    System.out.println(sum);
	}

	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;
		int gcd = 1;
	    for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    }
	    System.out.println(sum);
	}

	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;
		int gcd = 1;
	    for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    }
	    System.out.println(sum);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;
		int gcd = 1;
	    for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    }
	    System.out.println(sum);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc long sum = 0; sum 0 int gcd = 1; gcd 1 for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    } int i = 1; int i = 1; i 1 i <= num i num i++ i++ i {
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    } {
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    } for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    } int j = 1; int j = 1; j 1 j <= num j num j++ j++ j {
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    } {
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    } for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    } int k = 1; int k = 1; k 1 k <= num k num k++ k++ k {
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    } {
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    } if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	} i == 1 || j == 1 || k == 1 i == 1 || j == 1 || k == 1 i == 1 i 1 j == 1 j 1 k == 1 k 1 {
	    	    		sum += 1;
	    	    		continue;
	    	    	} sum += 1 sum 1 continue; {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	} sum += gcd(gcd(i,j),k) sum gcd(gcd(i,j),k) gcd gcd(i,j) gcd i j k System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    } gcd {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    } int r; r while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        } n > 0 n 0 {
            r = m % n;
            m = n;
            n = r;
        } r = m % n r m % n m n m = n m n n = r n r return m; m int m m int n n public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;
		int gcd = 1;
	    for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    }
	    System.out.println(sum);
	}

	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;
		int gcd = 1;
	    for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    }
	    System.out.println(sum);
	}

	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum = 0;
		int gcd = 1;
	    for(int i = 1; i <= num; i++){
	    	for(int j = 1; j <= num; j++){
	    		for(int k = 1; k <= num; k++){
	    	    	if(i == 1 || j == 1 || k == 1) {
	    	    		sum += 1;
	    	    		continue;
	    	    	}else {
	    	    		sum += gcd(gcd(i,j),k);
	    	    	}
	    	    }
		    }
	    }
	    System.out.println(sum);
	}

	public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
}
