import java.util.*;

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


       
    import java.util.*; util.* java public class Main{
    static int gcd(int a,int b){
        if(b == 0) return a;
        return gcd(b,a%b);
    }
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();
        int sum=0;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            }
        }
        System.out.println(sum);
    }
} Main static int gcd(int a,int b){
        if(b == 0) return a;
        return gcd(b,a%b);
    } gcd {
        if(b == 0) return a;
        return gcd(b,a%b);
    } if(b == 0) return a; b == 0 b 0 return a; a 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){
        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();
        int sum=0;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            }
        }
        System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();
        int sum=0;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            }
        }
        System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int k=sc.nextInt(); k sc.nextInt() sc.nextInt sc int sum=0; sum 0 for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            }
        } int i=1; int i=1; i 1 i<=k i k i++ i++ i {
            for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            }
        } {
            for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            }
        } for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            } {
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            } for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                } int m=1; int m=1; m 1 m<=k m k m++ m++ m {
                    sum+=gcd(gcd(i,j),m);
                } {
                    sum+=gcd(gcd(i,j),m);
                } sum+=gcd(gcd(i,j),m) sum gcd(gcd(i,j),m) gcd gcd(i,j) gcd i j m System.out.println(sum) System.out.println System.out System System.out sum String[]args args public class Main{
    static int gcd(int a,int b){
        if(b == 0) return a;
        return gcd(b,a%b);
    }
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();
        int sum=0;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            }
        }
        System.out.println(sum);
    }
} public class Main{
    static int gcd(int a,int b){
        if(b == 0) return a;
        return gcd(b,a%b);
    }
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();
        int sum=0;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                for(int m=1;m<=k;m++){
                    sum+=gcd(gcd(i,j),m);
                }
            }
        }
        System.out.println(sum);
    }
} Main
import java.util.*;

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


       
   