#include<stdio.h>
long long int  gcd(long long int  a, long long int b)
{
    if(a%b==0)
    {
        return b; 
    }
    return gcd(b,a%b);
}
int main()
{
   long long int n,sum=0,a,b,c,d;
    scanf("%lld",&n);
    for (a = 1; a <= n; a++)
    {
         for ( b = 1; b <=n; b++)
         {
             for ( c = 1; c <=n; c++)
             {
                   d=gcd(a,b);
                   d=gcd(d,c);
                   sum+=d;
             }
         }
    }
      printf("%lld\n",sum);  
    
}