#include<stdio.h>
int gcd(int a, int b)
{
    if(a%b == 0)
    {
        return b;
    }else
    {
        return gcd(b, a%b);
    }
}



int main(void)
{
    
    int a,b,c,p,q;
    
    
    
    int k;
    long int sum = 0;
    scanf("%d",&k);
    for(a = 1 ; a <= k ; a++)
    {
        for(b = 1 ; b <= k ; b++)
        {
            for( c = 1 ; c <= k ; c++)
            {
                p = gcd(a,b);
                q = gcd(c,p);
                sum += q;
            }
        }
    }
    printf("%ld\n",sum);

}