#include <iostream>

using namespace std;

int gcd(int x,int y)
{
    int r;
    while(r = x%y)
    {
        x = y;
        y = r;
        r = x%y;
    }
    return y;
}

int main()
{
    int i,j,k,t,n;
    long long sum=0;
    cin >> n;
    for(i = 1;i <= n;i++)
        for(j = 1;j <= n;j++)
            for(k = 1;k <= n;k++)
            {
                t = gcd(i,k);
                sum += gcd(j,t);
            }
    cout << sum << endl;
    return 0;
}