#include <iostream>

int _gcd(int a, int b)
{

    return (a % b == 0) ? b : _gcd(b, a % b);
}

int gcd(int a, int b)
{
    return (a < b) ? _gcd(b, a) : _gcd(a, b);
}

int main()
{

    int n;

    std::cin >> n;

    int sum = 0;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            int g = gcd(i, j);
            for (int k = 1; k <= n; ++k)
                sum += gcd(g, k);
        }
    }

    std::cout << sum << std::endl;

    return 0;
}