import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int res = 0;
        
        for(int a = 1; a <= N; ++a){
            for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            }
        }
        System.out.println(res);
    }
    
    private static int greatestCommonFactor(int a, int b, int c)
    {
        int limit = Math.min(a, b);
        limit = Math.min(limit, c);
        for(int n = limit; n >= 2; n--)
        {
            if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            }
        }
        return 1;
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int res = 0;
        
        for(int a = 1; a <= N; ++a){
            for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            }
        }
        System.out.println(res);
    }
    
    private static int greatestCommonFactor(int a, int b, int c)
    {
        int limit = Math.min(a, b);
        limit = Math.min(limit, c);
        for(int n = limit; n >= 2; n--)
        {
            if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            }
        }
        return 1;
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int res = 0;
        
        for(int a = 1; a <= N; ++a){
            for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            }
        }
        System.out.println(res);
    } main {
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int res = 0;
        
        for(int a = 1; a <= N; ++a){
            for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            }
        }
        System.out.println(res);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int res = 0; res 0 for(int a = 1; a <= N; ++a){
            for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            }
        } int a = 1; int a = 1; a 1 a <= N a N ++a ++a a {
            for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            }
        } {
            for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            }
        } for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            } int b = 1; int b = 1; b 1 b <= N b N ++b ++b b {
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            } {
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            } for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                } int c = 1; int c = 1; c 1 c <= N c N ++c ++c c {
                    res += greatestCommonFactor(a, b, c);
                } {
                    res += greatestCommonFactor(a, b, c);
                } res += greatestCommonFactor(a, b, c) res greatestCommonFactor(a, b, c) greatestCommonFactor a b c System.out.println(res) System.out.println System.out System System.out res String[] args args private static int greatestCommonFactor(int a, int b, int c)
    {
        int limit = Math.min(a, b);
        limit = Math.min(limit, c);
        for(int n = limit; n >= 2; n--)
        {
            if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            }
        }
        return 1;
    } greatestCommonFactor {
        int limit = Math.min(a, b);
        limit = Math.min(limit, c);
        for(int n = limit; n >= 2; n--)
        {
            if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            }
        }
        return 1;
    } int limit = Math.min(a, b); limit Math.min(a, b) Math.min Math a b limit = Math.min(limit, c) limit Math.min(limit, c) Math.min Math limit c for(int n = limit; n >= 2; n--)
        {
            if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            }
        } int n = limit; int n = limit; n limit n >= 2 n 2 n-- n-- n {
            if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            }
        } {
            if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            }
        } if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            } (a % n == 0) && (b % n == 0) && (c % n == 0) (a % n == 0) && (b % n == 0) && (c % n == 0) (a % n == 0) a % n a n 0 (b % n == 0) b % n b n 0 (c % n == 0) c % n c n 0 {
                return n;
            } return n; n return 1; 1 int a a int b b int c c
import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int res = 0;
        
        for(int a = 1; a <= N; ++a){
            for(int b = 1; b <= N; ++b){
                for(int c = 1; c <= N; ++c){
                    res += greatestCommonFactor(a, b, c);
                }
 
            }
        }
        System.out.println(res);
    }
    
    private static int greatestCommonFactor(int a, int b, int c)
    {
        int limit = Math.min(a, b);
        limit = Math.min(limit, c);
        for(int n = limit; n >= 2; n--)
        {
            if ( (a % n == 0) && (b % n == 0) && (c % n == 0) ) {
                return n;
            }
        }
        return 1;
    }
}