#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;

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

ll gcd(ll a,ll b ,ll c){
 return gcd(c,gcd(a,b));
}


int main(){
 ll n;
 cin>>n;
 ll s = 0;
 for(ll i=1;i<=n;i++)
  for(ll j=1;j<=n;j++)
   for(ll k=1;k<=n;k++)
    s += gcd(i,j,k);
 cout<<s<<endl;
    return 0;
}
