#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int data[201][201];

int main(){
    int k;
    cin >> k;
    ll ans =0;

    rep(i, 202){
        rep(j, 202) data[i][j]=-1;
    }

    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            int ab;
            if(data[max(a,b)][min(a,b)]==-1) data[max(a,b)][min(a,b)] = gcd(a,b);
            ab = data[max(a,b)][min(a,b)];
            for(int c=1;c<=k;c++){
                int x,y;
                x= max(ab, c);
                y= min(ab, c);
                if(data[x][y]==-1) data[x][y] = gcd(x,y);
                ans+=data[x][y];
            }
        }
    }
    cout << ans << endl;
    return 0;
}