import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static int gcd(int a,int b){
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        long sum=0;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        }
        System.out.println(sum);
    }
} import java.io.*; io.* java import java.lang.*; lang.* java import java.util.*; util.* java public class Main{
    public static int gcd(int a,int b){
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        long sum=0;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        }
        System.out.println(sum);
    }
} Main public static int gcd(int a,int b){
        if(a%b==0) return b;
        return gcd(b,a%b);
    } gcd {
        if(a%b==0) return b;
        return gcd(b,a%b);
    } if(a%b==0) return b; a%b==0 a%b a b 0 return b; b return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b int a a int b b public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        long sum=0;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        }
        System.out.println(sum);
    } main {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        long sum=0;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        }
        System.out.println(sum);
    } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int N=Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br long sum=0; sum 0 for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        } int i=1; int i=1; i 1 i<=N i N i++ i++ i {
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        } {
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        } for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            } int j=1; int j=1; j 1 j<=N j N j++ j++ j {
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            } {
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            } for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                } int k=1; int k=1; k 1 k<=N k N k++ k++ k {
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                } {
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                } int m=gcd(i,gcd(j,k)); m gcd(i,gcd(j,k)) gcd i gcd(j,k) gcd j k sum+=m sum m System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main{
    public static int gcd(int a,int b){
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        long sum=0;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        }
        System.out.println(sum);
    }
} public class Main{
    public static int gcd(int a,int b){
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        long sum=0;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        }
        System.out.println(sum);
    }
} Main
import java.io.*;
import java.lang.*;
import java.util.*;
public class Main{
    public static int gcd(int a,int b){
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        long sum=0;
        for(int i=1;i<=N;i++){
            for(int j=1;j<=N;j++){
                for(int k=1;k<=N;k++){
                    int m=gcd(i,gcd(j,k));
                    sum+=m;
                }
            }
        }
        System.out.println(sum);
    }
}
