import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int sum = 0;
                for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                }
                System.out.println(sum);
    }
    public static int gcd(int a, int b){
        int tmp;
        while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int sum = 0;
                for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                }
                System.out.println(sum);
    }
    public static int gcd(int a, int b){
        int tmp;
        while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    }
} Main public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int sum = 0;
                for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                }
                System.out.println(sum);
    } main {
                Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int sum = 0;
                for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                }
                System.out.println(sum);
    } Scanner s = new Scanner(System.in); s new Scanner(System.in) int a = s.nextInt(); a s.nextInt() s.nextInt s int sum = 0; sum 0 for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                } int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                } {
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                } for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    } int j = 0; int j = 0; j 0 j < a j a j++ j++ j {
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    } {
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    } for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        } int k = 0; int k = 0; k 0 k < a k a k++ k++ k {
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        } {
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        } sum = sum + gcd(gcd(i+1,j+1),k+1) sum sum + gcd(gcd(i+1,j+1),k+1) sum gcd(gcd(i+1,j+1),k+1) gcd gcd(i+1,j+1) gcd i+1 i 1 j+1 j 1 k+1 k 1 System.out.println(sum) System.out.println System.out System System.out sum String[] args args public static int gcd(int a, int b){
        int tmp;
        while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    } gcd {
        int tmp;
        while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    } int tmp; tmp while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        } (tmp = a % b) != 0 (tmp = a % b) tmp a % b a b 0 {
            a = b;
            b = tmp;
        } a = b a b b = tmp b tmp return b; b int a a int b b public class Main{
    public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int sum = 0;
                for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                }
                System.out.println(sum);
    }
    public static int gcd(int a, int b){
        int tmp;
        while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    }
} public class Main{
    public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int sum = 0;
                for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                }
                System.out.println(sum);
    }
    public static int gcd(int a, int b){
        int tmp;
        while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                int a = s.nextInt();
                int sum = 0;
                for(int i = 0; i < a; i++){
                    for(int j = 0; j < a; j++){
                        for(int k = 0; k < a; k++){
                            sum = sum + gcd(gcd(i+1,j+1),k+1);
                        }
                    }
                }
                System.out.println(sum);
    }
    public static int gcd(int a, int b){
        int tmp;
        while ((tmp = a % b) != 0) {
            a = b;
            b = tmp;
        }
        return b;
    }
}