import java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        int num = key.nextInt();
        long sum = 0;
        int a = 1;
        int b = 1;
        int c = 1;
        for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        }
        System.out.println(sum);
    }
} import java.util.Scanner; Scanner java.util public class Main
{
    public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        int num = key.nextInt();
        long sum = 0;
        int a = 1;
        int b = 1;
        int c = 1;
        for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        }
        System.out.println(sum);
    }
} Main public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        int num = key.nextInt();
        long sum = 0;
        int a = 1;
        int b = 1;
        int c = 1;
        for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        }
        System.out.println(sum);
    } main {
        Scanner key = new Scanner(System.in);
        int num = key.nextInt();
        long sum = 0;
        int a = 1;
        int b = 1;
        int c = 1;
        for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        }
        System.out.println(sum);
    } Scanner key = new Scanner(System.in); key new Scanner(System.in) int num = key.nextInt(); num key.nextInt() key.nextInt key long sum = 0; sum 0 int a = 1; a 1 int b = 1; b 1 int c = 1; c 1 for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        } int i =1; int i =1; i 1 i<=num i num i++ i++ i {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        } {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        } for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            } int j = 1 ; int j = 1 ; j 1 j<=num j num j++ j++ j {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            } {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            } for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                } int k = 1; int k = 1; k 1 k<=num k num k++ k++ k {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                } {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                } a = i a i b = j b j c = k c k int min = Math.min(a,b); min Math.min(a,b) Math.min Math a b min = Math.min(min,c) min Math.min(min,c) Math.min Math min c sum = sum +min sum sum +min sum min System.out.println(sum) System.out.println System.out System System.out sum String [] args args public class Main
{
    public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        int num = key.nextInt();
        long sum = 0;
        int a = 1;
        int b = 1;
        int c = 1;
        for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        }
        System.out.println(sum);
    }
} public class Main
{
    public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        int num = key.nextInt();
        long sum = 0;
        int a = 1;
        int b = 1;
        int c = 1;
        for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        }
        System.out.println(sum);
    }
} Main
import java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        int num = key.nextInt();
        long sum = 0;
        int a = 1;
        int b = 1;
        int c = 1;
        for(int i =1; i<=num ; i++)
        {
            for(int j = 1 ; j<=num ; j++)
            {
                for(int k = 1; k<=num; k++)
                {
                    a = i;
                    b = j;
                    c = k;
                    int min = Math.min(a,b);
                    min = Math.min(min,c);
                    end:
                    for(int l = min; l>=1; l--)
                    {
                        if((a % l == 0) && (b % l == 0 )&& (c % l == 0))
                        {
                            min = l;
                            break end;
                        }
                    }
                    
                    
                    sum = sum +min;
                    
                    
                    
                }
            }
        }
        System.out.println(sum);
    }
}