#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int64_t gcd(int64_t a, int64_t b)
{
    if(a % b == 0)
    {
        return b;
    }

    return gcd(b, a % b);
}

void Main()
{
    int64_t K;
    cin >> K;
    
    int64_t result = 0;
    for(int64_t i = 1; i <= K; ++i)
    {
        for(int64_t j = 1; j <= K; ++j)
        {
            for(int64_t k = 1; k <= K; ++k)
            {
                result += gcd(gcd(i, j), k);
            }
        }
    }

    cout << result << endl;
}

int main()
{
    Main();
}
