import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(reader.readLine());
        long count=0;
        for (long i = 1; i <= n; i++) {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        }
        System.out.println(count);
    }
    static long gcd(long a,long b){
        if (b==0)
            return a;
        else
            return gcd(b,a%b);
    }
    static long gcd3(long a,long b,long c){
        return gcd(gcd(a,b),c);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(reader.readLine());
        long count=0;
        for (long i = 1; i <= n; i++) {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        }
        System.out.println(count);
    }
    static long gcd(long a,long b){
        if (b==0)
            return a;
        else
            return gcd(b,a%b);
    }
    static long gcd3(long a,long b,long c){
        return gcd(gcd(a,b),c);
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(reader.readLine());
        long count=0;
        for (long i = 1; i <= n; i++) {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        }
        System.out.println(count);
    } main {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(reader.readLine());
        long count=0;
        for (long i = 1; i <= n; i++) {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        }
        System.out.println(count);
    } BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) long n=Long.parseLong(reader.readLine()); n Long.parseLong(reader.readLine()) Long.parseLong Long reader.readLine() reader.readLine reader long count=0; count 0 for (long i = 1; i <= n; i++) {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        } long i = 1; long i = 1; i 1 i <= n i n i++ i++ i {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        } {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        } for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            } long j = 1; long j = 1; j 1 j <=n j n j++ j++ j {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            } {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            } for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                } long k = 1; long k = 1; k 1 k <=n k n k++ k++ k {
                    count+=gcd3(i,j,k);
                } {
                    count+=gcd3(i,j,k);
                } count+=gcd3(i,j,k) count gcd3(i,j,k) gcd3 i j k System.out.println(count) System.out.println System.out System System.out count String[] args args static long gcd(long a,long b){
        if (b==0)
            return a;
        else
            return gcd(b,a%b);
    } gcd {
        if (b==0)
            return a;
        else
            return gcd(b,a%b);
    } if (b==0)
            return a;
        else
            return gcd(b,a%b); b==0 b 0 return a; a return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b static long gcd3(long a,long b,long c){
        return gcd(gcd(a,b),c);
    } gcd3 {
        return gcd(gcd(a,b),c);
    } return gcd(gcd(a,b),c); gcd(gcd(a,b),c) gcd gcd(a,b) gcd a b c long a a long b b long c c public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(reader.readLine());
        long count=0;
        for (long i = 1; i <= n; i++) {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        }
        System.out.println(count);
    }
    static long gcd(long a,long b){
        if (b==0)
            return a;
        else
            return gcd(b,a%b);
    }
    static long gcd3(long a,long b,long c){
        return gcd(gcd(a,b),c);
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(reader.readLine());
        long count=0;
        for (long i = 1; i <= n; i++) {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        }
        System.out.println(count);
    }
    static long gcd(long a,long b){
        if (b==0)
            return a;
        else
            return gcd(b,a%b);
    }
    static long gcd3(long a,long b,long c){
        return gcd(gcd(a,b),c);
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(reader.readLine());
        long count=0;
        for (long i = 1; i <= n; i++) {
            for (long j = 1; j <=n ; j++) {
                for (long k = 1; k <=n ; k++) {
                    count+=gcd3(i,j,k);
                }
            }
        }
        System.out.println(count);
    }
    static long gcd(long a,long b){
        if (b==0)
            return a;
        else
            return gcd(b,a%b);
    }
    static long gcd3(long a,long b,long c){
        return gcd(gcd(a,b),c);
    }
}