
import java.math.BigInteger;
import java.util.Scanner;


public class Main {
    public static int gcd(int a,int b)
    {
        if(b==0)
             return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
     long  sum=0;
     for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     }

     System.out.println(sum);

    }
} import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util public class Main {
    public static int gcd(int a,int b)
    {
        if(b==0)
             return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
     long  sum=0;
     for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     }

     System.out.println(sum);

    }
} Main public static int gcd(int a,int 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 int a a int b b public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
     long  sum=0;
     for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     }

     System.out.println(sum);

    } main {

     Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
     long  sum=0;
     for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     }

     System.out.println(sum);

    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc long  sum=0; sum 0 for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     } int i = 1; int i = 1; i 1 i<=n i n i++ i++ i {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     } {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     } for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         } int j=1; int j=1; j 1 j<=n j n j++ j++ j {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         } {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         } for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k)); int k=1; int k=1; k 1 k<=n k n k++ k++ k sum+=gcd(i,gcd(j,k)); sum+=gcd(i,gcd(j,k)) sum gcd(i,gcd(j,k)) gcd i gcd(j,k) gcd j k System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
    public static int gcd(int a,int b)
    {
        if(b==0)
             return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
     long  sum=0;
     for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     }

     System.out.println(sum);

    }
} public class Main {
    public static int gcd(int a,int b)
    {
        if(b==0)
             return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
     long  sum=0;
     for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     }

     System.out.println(sum);

    }
} Main

import java.math.BigInteger;
import java.util.Scanner;


public class Main {
    public static int gcd(int a,int b)
    {
        if(b==0)
             return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
     long  sum=0;
     for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     }

     System.out.println(sum);

    }
}
