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

typedef long long ll;

ll gcd(ll a, ll b){
    if(a<b) return gcd(b,a);
    ll r;
    while(r=a%b){
        a = b; b = r;
    }
    return b;
}

int main(){
    ll K;
    cin >> K ;
    ll ans = 0;
    for(ll i = 1; i <= K; i++){
        for(ll j = i; j <= K; j++){
            for(ll k = j; k <= K; k++){
                ll tmp = gcd(i,j);
                tmp = gcd(tmp, k);
                if(i == j && j == k){
                    ans += tmp;
                } else if(i ==j || j == k || i == k){
                    ans += tmp * 3;
                } else { 
                    ans += tmp * 6;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
