import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long K = sc.nextLong(); 
        sc.nextLine();
        long sum = new Long(0);

        for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        }
        System.out.println(sum);
    }

     static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    static long gcdtrip(long a, long b, long c) {
        return gcd(a,gcd(b,c)) ;
    }

    static int check(int a, int b, int c) {
        if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long K = sc.nextLong(); 
        sc.nextLine();
        long sum = new Long(0);

        for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        }
        System.out.println(sum);
    }

     static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    static long gcdtrip(long a, long b, long c) {
        return gcd(a,gcd(b,c)) ;
    }

    static int check(int a, int b, int c) {
        if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long K = sc.nextLong(); 
        sc.nextLine();
        long sum = new Long(0);

        for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        }
        System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        
        long K = sc.nextLong(); 
        sc.nextLine();
        long sum = new Long(0);

        for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        }
        System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long K = sc.nextLong(); K sc.nextLong() sc.nextLong sc sc.nextLine() sc.nextLine sc long sum = new Long(0); sum new Long(0) for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        } int i = 1; int i = 1; i 1 i <= K i K i++ i++ i {
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        } {
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        } for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            } int j = i; int j = i; j i j <= K j K j++ j++ j {
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            } {
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            } for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                } int k = j; int k = j; k j k <= K k K k++ k++ k {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                } {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                } sum += gcdtrip(i, j, k)*check(i, j, k) sum gcdtrip(i, j, k)*check(i, j, k) gcdtrip(i, j, k) gcdtrip i j k check(i, j, k) check i j k System.out.println(sum) System.out.println System.out System System.out sum String[] args args static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } gcd {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n static long gcdtrip(long a, long b, long c) {
        return gcd(a,gcd(b,c)) ;
    } gcdtrip {
        return gcd(a,gcd(b,c)) ;
    } return gcd(a,gcd(b,c)) ; gcd(a,gcd(b,c)) gcd a gcd(b,c) gcd b c long a a long b b long c c static int check(int a, int b, int c) {
        if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        }
    } check {
        if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        }
    } if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        } a == b && a == c && b == a a == b && a == c && b == a a == b a b a == c a c b == a b a {
            return 1;
        } return 1; 1 if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        } a == b || b == c || a == c a == b || b == c || a == c a == b a b b == c b c a == c a c {
            return 3;
        } return 3; 3 {
            return 6;
        } return 6; 6 int a a int b b int c c public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long K = sc.nextLong(); 
        sc.nextLine();
        long sum = new Long(0);

        for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        }
        System.out.println(sum);
    }

     static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    static long gcdtrip(long a, long b, long c) {
        return gcd(a,gcd(b,c)) ;
    }

    static int check(int a, int b, int c) {
        if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long K = sc.nextLong(); 
        sc.nextLine();
        long sum = new Long(0);

        for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        }
        System.out.println(sum);
    }

     static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    static long gcdtrip(long a, long b, long c) {
        return gcd(a,gcd(b,c)) ;
    }

    static int check(int a, int b, int c) {
        if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long K = sc.nextLong(); 
        sc.nextLine();
        long sum = new Long(0);

        for(int i = 1; i <= K; i++){
            for(int j = i; j <= K; j++){
                for(int k = j; k <= K; k++) {
                    sum += gcdtrip(i, j, k)*check(i, j, k);
                }
            }
        }
        System.out.println(sum);
    }

     static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    static long gcdtrip(long a, long b, long c) {
        return gcd(a,gcd(b,c)) ;
    }

    static int check(int a, int b, int c) {
        if (a == b && a == c && b == a) {
            return 1;
        } else if (a == b || b == c || a == c) {
            return 3;
        } else {
            return 6;
        }
    }
}