#include <bits/stdc++.h>
#define rep(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main(){
    ll n;
    cin >> n;

    ll sum=0;
    rep(i,n){
        rep(j,n){
            rep(h,n){
                sum += gcd(i,gcd(j,h));
            }
        }
    }

    cout << sum << endl;

    return 0;
}

