#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main(){
    ll k, ans = 0; cin >> k;
    for(ll i = 1; i <= k; ++i){
       for(ll j = 1; j <= k; ++j){
            for(ll x = 1; x <= k; ++x){
                ans += __gcd(i, __gcd(j, x));
            }
        }
    }
    cout << ans;
    return 0;
}
