#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
ll gcd(ll a,ll b){
  if(a<b) return gcd(b,a);
  if(b==0) return a;
  else return gcd(a%b,b);
}

int main(){
  ll k;
  cin>>k;
  ll sum=0;
  ll x=0;
  ll y=0;
  rep(i,k){
    rep(j,k){
        x=gcd(i+1,j+1);
      rep(l,k){
        y=gcd(x,l+1);
        sum+=y;
      }
    }
        }
        cout<<sum<<endl;
}