#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b)
{
    if (a < b)
        return gcd(b, a);
    unsigned r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int k;
cin >> k;
ll total = 0;
reps(a,k+1,1){
    reps(b,k+1,1){
        reps(c,k+1,1){
            total += gcd(a, gcd(b, c));
        }
}
}
cout << total << endl;
//system("pause");
return 0;
}