import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        long total=0;

        for(int i=1; i<=K; i++){
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        }
        System.out.println(total);
    }

    public static int gcd(int a, int b) {
        int r = a % b;
        if(r==0){
            return b;
        }else{
            return gcd(b,r);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        long total=0;

        for(int i=1; i<=K; i++){
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        }
        System.out.println(total);
    }

    public static int gcd(int a, int b) {
        int r = a % b;
        if(r==0){
            return b;
        }else{
            return gcd(b,r);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        long total=0;

        for(int i=1; i<=K; i++){
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        }
        System.out.println(total);
    } main {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        long total=0;

        for(int i=1; i<=K; i++){
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        }
        System.out.println(total);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int K = sc.nextInt(); K sc.nextInt() sc.nextInt sc long total=0; total 0 for(int i=1; i<=K; i++){
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        } int i=1; int i=1; i 1 i<=K i K i++ i++ i {
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        } {
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        } for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            } int j = 1; int j = 1; j 1 j<=K j K j++ j++ j {
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            } {
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            } for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                } int l=1; int l=1; l 1 l<=K l K l++ l++ l {
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                } {
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                } total += gcd(gcd(i, j),l) total gcd(gcd(i, j),l) gcd gcd(i, j) gcd i j l System.out.println(total) System.out.println System.out System System.out total String[] args args public static int gcd(int a, int b) {
        int r = a % b;
        if(r==0){
            return b;
        }else{
            return gcd(b,r);
        }
    } gcd {
        int r = a % b;
        if(r==0){
            return b;
        }else{
            return gcd(b,r);
        }
    } int r = a % b; r a % b a b if(r==0){
            return b;
        }else{
            return gcd(b,r);
        } r==0 r 0 {
            return b;
        } return b; b {
            return gcd(b,r);
        } return gcd(b,r); gcd(b,r) gcd b r int a a int b b public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        long total=0;

        for(int i=1; i<=K; i++){
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        }
        System.out.println(total);
    }

    public static int gcd(int a, int b) {
        int r = a % b;
        if(r==0){
            return b;
        }else{
            return gcd(b,r);
        }
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        long total=0;

        for(int i=1; i<=K; i++){
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        }
        System.out.println(total);
    }

    public static int gcd(int a, int b) {
        int r = a % b;
        if(r==0){
            return b;
        }else{
            return gcd(b,r);
        }
    }
} Main
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        long total=0;

        for(int i=1; i<=K; i++){
            for(int j = 1; j<=K; j++){
                for(int l=1; l<=K; l++){
                    total += gcd(gcd(i, j),l);
                    // System.out.println(gcd(gcd(i, j),l));
                }
            }
        }
        System.out.println(total);
    }

    public static int gcd(int a, int b) {
        int r = a % b;
        if(r==0){
            return b;
        }else{
            return gcd(b,r);
        }
    }
}