#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<long , long> pll;

const ll mx = 105;
const ll maxn = 1000001;
const ll mod = 1000000007;

vector<vector<int>> adj;
vector<int> res;
vector<int> ord;

int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(0);
   
   ll n, m, i, j, k, l, res = 0;

   cin>>k;

   for(i = 1;i <= k;i++){

       for(j = 1;j <= k;j++){
           for(l = 1;l <= k;l++){
                
                res += __gcd(i, __gcd(j, l));
           }
       }

   }
   cout<<res<<"\n";
}


