import java.util.Scanner;

public class Main {
    public static void main(String[] args){

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

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

        int sum=0;
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        for(int i=1;i<=a;i++){
            for(int j=1;j<=a;j++){
                for(int k=1;k<=a;k++){
                    int g=gcd(i,j);
                    int g2=gcd(g,k);
                    sum+=g2;
                }
            }
        }
      System.out.println(sum);
    } main {

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

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

        int sum=0;
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        for(int i=1;i<=a;i++){
            for(int j=1;j<=a;j++){
                for(int k=1;k<=a;k++){
                    int g=gcd(i,j);
                    int g2=gcd(g,k);
                    sum+=g2;
                }
            }
        }
      System.out.println(sum);
    }
    public static int gcd(int a,int b){
        if(a<b){
            int tmp=a;
            a=b;
            b=tmp;
        }
        int r=a%b;
        while(r!=0){
            a = b;
            b = r;
          	r = a % b;
        }
        return b;
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        int sum=0;
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        for(int i=1;i<=a;i++){
            for(int j=1;j<=a;j++){
                for(int k=1;k<=a;k++){
                    int g=gcd(i,j);
                    int g2=gcd(g,k);
                    sum+=g2;
                }
            }
        }
      System.out.println(sum);
    }
    public static int gcd(int a,int b){
        if(a<b){
            int tmp=a;
            a=b;
            b=tmp;
        }
        int r=a%b;
        while(r!=0){
            a = b;
            b = r;
          	r = a % b;
        }
        return b;
    }
}