#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef long long ll;


int gcd(int n1,int n2)
{
    int keep,r;
    if(n1<n2)
    {
        keep=n1;
        n1=n2;
        n2=keep;
    }
    if(n2==1)
    {
        return 1;
    }
    else
    {
    r=n1%n2;
    while(r!=0)
    {
        n1=n2;
        n2=r;
        r=n1%n2;
    }
    return n2;
    }
}

int main()
{
    int k;
    ll ans=0;
    
    scanf("%d",&k);

    for(int a=1;a<k+1;a++)
    {
        for(int b=1;b<k+1;b++)
        {
            for(int c=1;c<k+1;c++)
            {
                ans=ans+gcd(a,gcd(b,c));
            }
        }
    }

    printf("%lld\n",ans);
}