import java.util.Scanner;

class Main {

    static int gcd(int x,int y){
        while(y!=0){
            int r=x%y;
            x=y;
            y=r;
        }
        return x;
    }

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);
        
        int x=stdIn.nextInt();
        System.out.println();
        int sum=0;
        for(int i=1; i<=x; i++){
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        }
        System.out.println(sum);
        
        
       
        
    }

} import java.util.Scanner; Scanner java.util class Main {

    static int gcd(int x,int y){
        while(y!=0){
            int r=x%y;
            x=y;
            y=r;
        }
        return x;
    }

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);
        
        int x=stdIn.nextInt();
        System.out.println();
        int sum=0;
        for(int i=1; i<=x; i++){
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        }
        System.out.println(sum);
        
        
       
        
    }

} Main static int gcd(int x,int y){
        while(y!=0){
            int r=x%y;
            x=y;
            y=r;
        }
        return x;
    } gcd {
        while(y!=0){
            int r=x%y;
            x=y;
            y=r;
        }
        return x;
    } while(y!=0){
            int r=x%y;
            x=y;
            y=r;
        } y!=0 y 0 {
            int r=x%y;
            x=y;
            y=r;
        } int r=x%y; r x%y x y x=y x y y=r y r return x; x int x x int y y public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);
        
        int x=stdIn.nextInt();
        System.out.println();
        int sum=0;
        for(int i=1; i<=x; i++){
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        }
        System.out.println(sum);
        
        
       
        
    } main {
        Scanner stdIn=new Scanner(System.in);
        
        int x=stdIn.nextInt();
        System.out.println();
        int sum=0;
        for(int i=1; i<=x; i++){
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        }
        System.out.println(sum);
        
        
       
        
    } Scanner stdIn=new Scanner(System.in); stdIn new Scanner(System.in) int x=stdIn.nextInt(); x stdIn.nextInt() stdIn.nextInt stdIn System.out.println() System.out.println System.out System System.out int sum=0; sum 0 for(int i=1; i<=x; i++){
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        } int i=1; int i=1; i 1 i<=x i x i++ i++ i {
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        } {
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        } for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            } int j=1; int j=1; j 1 j<=x j x j++ j++ j {
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            } {
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            } for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                } int k=1; int k=1; k 1 k<=x k x k++ k++ k {
                    sum+=gcd(gcd(i,j),k);
                } {
                    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
import java.util.Scanner;

class Main {

    static int gcd(int x,int y){
        while(y!=0){
            int r=x%y;
            x=y;
            y=r;
        }
        return x;
    }

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);
        
        int x=stdIn.nextInt();
        System.out.println();
        int sum=0;
        for(int i=1; i<=x; i++){
            for(int j=1; j<=x; j++){
                for(int k=1; k<=x; k++){
                    sum+=gcd(gcd(i,j),k);
                }
            }
        }
        System.out.println(sum);
        
        
       
        
    }

}