#include <iostream>
#include <algorithm>
using namespace std;
 
int gcd(int a, int b) {
    return b == 0? a:gcd(b, a%b);
}

int gcdt(int a, int b, int c) {
    return gcd(a, gcd(b, c));
}

int main()
{
    int a, b, c;
    int k;
    cin >> k;
    long long sum = 0;
    for (a = 1; a <= k; ++a)
        for (b = 1; b <= k; ++b)
            for (c = 1; c <= k; ++c){
                sum += gcdt(a, b, c);
            }
            cout << sum << endl;
    return 0;
}