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

ll gcd(ll l, ll m){
    ll tmp;
    // cout << l << m << endl;
    if(m > l){
        tmp = m;
        m = l;
        l = tmp;
    }
    while ((1)){
        ll s;
        s = l % m;
        if(s == 0) return m;
        tmp = m;
        m = s;
        l = tmp;
    }
}

    
ll gcd3(ll l, ll m, ll n){
    return gcd(gcd(l,m),n);
}

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