#include <bits/stdc++.h>
using namespace std;

int memo[210][210];

int gcd(int x, int y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main(void) {
    int K;
    cin >> K;

    for (int i = 1; i < 210; i++) {
        for (int j = 1; j < 210; j++) {
            memo[i][j] = gcd(i, j);
        }
    }
    long long sum = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                sum += memo[memo[i][j]][k];
            }
        }
    }
    printf("%lld\n", sum);
    return 0;
}
