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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll k;
    cin >> k;
    int a,b,c;
    ll ans = 0;
    for(a = 1;a <= k;++a){
        for(b = 1;b <= k;++b){
            for(c = 1;c <= k;++c){
                ll tmp = gcd(a,b);
                tmp = gcd(tmp,c);
                ans += tmp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}