#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;

// 最大公約数
long long gcd(long long a, long long b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (b == 0) return a;
    else return gcd(b, a % b);
}

// 最小公倍数
long long lcm(long long a, long long b) {
    long long g = gcd(a, b);
    return a / g * b;
}

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