#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int main(){
FASTIO  
ll k;
cin>>k;
ll ans=0;
for(ll i=1;i<=k;i++){
  for(ll j=1;j<=k;j++){
     for(ll p=1;p<=k;p++){
        ans+=(ll)(__gcd(i,__gcd(j,p)));
     }
  }
}
cout<<ans;
return 0;
}
