/*
          .  .
          |\_|\
          | a_a\
          | | "]
      ____| '-\___
     /.----.___.-'\
    //        _    \
   //   .-. (~v~) /|
  |'|  /\:  .--  / \
 // |-/  \_/____/\/~|
|/  \ |  []_|_|_] \ |
| \  | \ |___   _\ ]_}
| |  '-' /   '.'  |
| |     /    /|:  |
| |     |   / |:  /\
| |     /  /  |  /  \
| |    |  /  /  |    \
\ |    |/\/  |/|/\    \
 \|\ |\|  |  | / /\/\__\
  \ \| | /   | |__
       / |   |____)
       |_/
*/

#include<bits/stdc++.h>

#define iamabatman ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precision cout.precision(10); cout << fixed;
#define endl '\n'

#define ll long long int
#define ull unsigned long long int
#define ld long double
const int INF = 1<<29;
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pii pair<int,int>
#define vi vector<int>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;

int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void solve()
{
  int n,ans=0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=n;j++)
    {
      for(int k=1;k<=n;k++)
      {
        ans+=gcd(k,gcd(i,j));
      }
    }
  }
  cout<<ans;

}


int main()
{

  iamabatman
  precision

  int t=1;
  //cin>>t;
  for(int ha=1;ha<=t;ha++)
  {
    //cout<<"Case #"<<ha<<": ";
    solve();
  }
  return 0;
}

