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 Exception{
        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++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            }
        }
        System.out.println(total);
    }
} 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 Exception{
        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++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            }
        }
        System.out.println(total);
    }
} 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 Exception{
        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++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,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++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,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++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            }
        } int i=1; int i=1; i 1 i<=k i k i++ i++ i {
            for(int j=1;j<=k;j++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            }
        } {
            for(int j=1;j<=k;j++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            }
        } for(int j=1;j<=k;j++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            } {
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            } int g=gcd((int)Math.max(i,j),(int)Math.min(i,j)); g gcd((int)Math.max(i,j),(int)Math.min(i,j)) gcd (int)Math.max(i,j) Math.max Math i j (int)Math.min(i,j) Math.min Math i j for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                } int l=1; int l=1; l 1 l<=k l k l++ l++ l {
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                } {
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                } total+=gcd((int)Math.max(g,l),(int)Math.min(g,l)) total gcd((int)Math.max(g,l),(int)Math.min(g,l)) gcd (int)Math.max(g,l) Math.max Math g l (int)Math.min(g,l) Math.min Math g l System.out.println(total) System.out.println System.out System System.out total 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 Exception{
        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++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            }
        }
        System.out.println(total);
    }
} 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 Exception{
        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++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            }
        }
        System.out.println(total);
    }
} Main
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 Exception{
        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++){
                int g=gcd((int)Math.max(i,j),(int)Math.min(i,j));
                for(int l=1;l<=k;l++){
                    total+=gcd((int)Math.max(g,l),(int)Math.min(g,l));
                }
            }
        }
        System.out.println(total);
    }
}