#include <bits/stdc++.h>

using namespace std;

int main()
{
    int k;
    cin>>k;
    long long sum=0;
    for(int i=1; i<=k; i++)
    {
        for(int x=1; x<=k; x++)
        {
            for(int j=1; j<=k; j++)
            {
                int cj=j, cx=x, ci=i;
                int gcd=1;
                while (j != 0)
                {
                    gcd = x % j;
                    x = j;
                    j = gcd;
                }
                int r=1;
                while (x != 0)
                {
                    r = i % x;
                    i = x;
                    x = r;
                }
                sum+=i;
                j=cj;
                x=cx;
                i=ci;
            }
        }
    }
    cout<<sum;
    return 0;
}
