#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
typedef long long ll;
using namespace std;

int main(){
    IOS
    int k;
    cin >> k;
    ll sum = 0;
    FOR(i,1,k){
        FOR(j,1,k){
            FOR(l,1,k){
                sum += __gcd(__gcd(i,j),l);
            }
        }
    }
    cout << sum;
    return 0;
}