#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
int gcd(int a,int b){
    if(a < b) return gcd(b, a);
    int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
signed main(){
    int n;cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            int ab=gcd(i,j);
            for(int k=1;k<=n;k++){
                sum+=gcd(ab,k);
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}