import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
    static int gcd(int a,int b){
        if(a==0){
            return b;
        }
        if(b==0){
            return a;
        }
        if(a>b){
            return gcd(a%b,b);
        }
        return gcd(a,b%a);

    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.HashMap; HashMap java.util public class Main {
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
    static int gcd(int a,int b){
        if(a==0){
            return b;
        }
        if(b==0){
            return a;
        }
        if(a>b){
            return gcd(a%b,b);
        }
        return gcd(a,b%a);

    }
} Main public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    } main {
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    } try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        } catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        } Exception e {
            System.out.println("KKKK "+e.getMessage());
        } System.out.println("KKKK "+e.getMessage()) System.out.println System.out System System.out "KKKK "+e.getMessage() "KKKK " e.getMessage() e.getMessage e {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        } BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int t=Integer.parseInt(br.readLine()); t Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br long sum=0; sum 0 for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            } int i=1; int i=1; i 1 i<=t i t i++ i++ i {
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            } {
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            } for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                } int j=1; int j=1; j 1 j<=t j t j++ j++ j {
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                } {
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                } for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    } int k=1; int k=1; k 1 k<=t k t k++ k++ k {
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    } {
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    } int u=gcd(j,k); u gcd(j,k) gcd j k int p=gcd(i,u); p gcd(i,u) gcd i u sum+=p sum p System.out.println(sum) System.out.println System.out System System.out sum String[] args args static int gcd(int a,int b){
        if(a==0){
            return b;
        }
        if(b==0){
            return a;
        }
        if(a>b){
            return gcd(a%b,b);
        }
        return gcd(a,b%a);

    } gcd {
        if(a==0){
            return b;
        }
        if(b==0){
            return a;
        }
        if(a>b){
            return gcd(a%b,b);
        }
        return gcd(a,b%a);

    } if(a==0){
            return b;
        } a==0 a 0 {
            return b;
        } return b; b if(b==0){
            return a;
        } b==0 b 0 {
            return a;
        } return a; a if(a>b){
            return gcd(a%b,b);
        } a>b a b {
            return gcd(a%b,b);
        } return gcd(a%b,b); gcd(a%b,b) gcd a%b a b b return gcd(a,b%a); gcd(a,b%a) gcd a b%a b a int a a int b b public class Main {
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
    static int gcd(int a,int b){
        if(a==0){
            return b;
        }
        if(b==0){
            return a;
        }
        if(a>b){
            return gcd(a%b,b);
        }
        return gcd(a,b%a);

    }
} public class Main {
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
    static int gcd(int a,int b){
        if(a==0){
            return b;
        }
        if(b==0){
            return a;
        }
        if(a>b){
            return gcd(a%b,b);
        }
        return gcd(a,b%a);

    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            long sum=0;
            for(int i=1;i<=t;i++){
                for(int j=1;j<=t;j++){
                    for(int k=1;k<=t;k++){
                        int u=gcd(j,k);
                        int p=gcd(i,u);
                        sum+=p;
                    }
                }
            }
            System.out.println(sum);

        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
    static int gcd(int a,int b){
        if(a==0){
            return b;
        }
        if(b==0){
            return a;
        }
        if(a>b){
            return gcd(a%b,b);
        }
        return gcd(a,b%a);

    }
}
