#include <iostream>

using namespace std;

long long int n, i, j, k, s, a, b, r, c, a1;

int main()
{
    cin >> n;
    for(i = 1; i <= n; i++)
        for(j = 1; j <= n; j++)
        {
            a = i;
            b = j;
            if(a < b)
                swap(a, b);
            while(b != 0)
            {
                r = a % b;
                a = b;
                b = r;
            }
            a1 = a;
            for(k = 1; k <= n; k++)
            {
                c++;
                b = k;
                a = a1;
                if(a < b)
                    swap(a, b);
                while(b != 0)
                {
                    r = a % b;
                    a = b;
                    b = r;
                }
                s += a;
            }
        }
    cout << s;
    return 0;
}
