#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
int main() {
    int k;
    cin >>k;
    
    ll total = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <=k; b++) {
            for (int c = 1; c <= k; c++) {
                total += gcd(a, gcd(b, c));
            }
        }
    }
    cout << total << endl;
    return 0;
}
