#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int k;
    int ans = 0;
    cin >> 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 += __algo_gcd(a, __algo_gcd(b, c));
            }
        }
    }
    cout << ans << endl;
}