#include<bits/stdc++.h>
using namespace std;
int p,sum;
#define MAXN 305
int f[MAXN][MAXN];

int gcd(int a,int b)
{
    //if(!b)return a;
    //return gcd(b,a%b);
    if(f[a][b]!=-1)return f[a][b];
    else
    {
        int aa=a,bb=b;
        int c;
        while(b)
        {
            c=a%b;
            a=b;
            b=c;
        }
        return f[aa][bb]=a;
    }
}
int main()
{
    memset(f,-1,sizeof f);
    scanf("%d",&p);
    for(int i=1;i<=p;i++)
    for(int j=1;j<=p;j++)
    for(int k=1;k<=p;k++)
    {
        sum+=gcd(gcd(i,j),k);
    }
    printf("%d\n",sum);
    return 0 ;
}
