#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

ll gcd (ll a, ll b) { return b?gcd(b,a%b): a;}

int main() {
    int k; cin >> k;
    vector<vector<ll>> a(210, vector<ll>(210, 1));
    repf(i,1,201) repf(j,i,201) {
        a[i][j] = a[j][i] = gcd(i,j);
    }

    ll ans = 0;
    repf(i,1,k+1) repf(j,1,k+1) repf(l,1,k+1) {
        ans += gcd(i, a[j][l]);
    }
    cout << ans << endl;
    return 0;
}