#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define en '\n'

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll a, sum = 0;
    cin >> a;
    for(int i = 1; i <= a; ++i){
        for(int j = 1; j <= a; ++j){
            for(int k = 1; k <= a; ++k){
                sum += gcd(i, gcd(j, k));
            }
        }
    }
    cout << sum;
}