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

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) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int k = Integer.parseInt(reader.readLine());

        long ans=0;
        
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        }

        System.out.println(ans);

    }
} 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 int gcd(int a,int b)
    {
        if(b==0)
            return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int k = Integer.parseInt(reader.readLine());

        long ans=0;
        
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        }

        System.out.println(ans);

    }
} 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) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int k = Integer.parseInt(reader.readLine());

        long ans=0;
        
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        }

        System.out.println(ans);

    } main {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int k = Integer.parseInt(reader.readLine());

        long ans=0;
        
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        }

        System.out.println(ans);

    } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) int k = Integer.parseInt(reader.readLine()); k Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader long ans=0; ans 0 for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        } int i=1; int i=1; i 1 i<=k i k i++ i++ i {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        } {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        } for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            } int j=1; int j=1; j 1 j<=k j k j++ j++ j {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            } {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            } for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                } int l=1; int l=1; l 1 l<=k l k l++ l++ l {
                    ans+=gcd(gcd(i,j),l);
                } {
                    ans+=gcd(gcd(i,j),l);
                } ans+=gcd(gcd(i,j),l) ans gcd(gcd(i,j),l) gcd gcd(i,j) gcd i j l System.out.println(ans) System.out.println System.out System System.out ans 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) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int k = Integer.parseInt(reader.readLine());

        long ans=0;
        
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        }

        System.out.println(ans);

    }
} 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) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int k = Integer.parseInt(reader.readLine());

        long ans=0;
        
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        }

        System.out.println(ans);

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

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) throws IOException {
        // write your code here

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int k = Integer.parseInt(reader.readLine());

        long ans=0;
        
        for(int i=1;i<=k;i++)
        {
            for(int j=1;j<=k;j++)
            {
                for(int l=1;l<=k;l++)
                {
                    ans+=gcd(gcd(i,j),l);
                }
            }
        }

        System.out.println(ans);

    }
}
