#include <bits/stdc++.h>
using namespace std;

int gcd(int m, int n){
   while (n != 0){
      int t = n;
      n = m % n;
      m = t;
   }
   return m;
}

int main(){
   int K;
   cin >> K;
   vector<int> gcd_ab;
   for (int m = K; m>0; m--){
      for (int n = K; n>0; n--){
         if (m > n){
            gcd_ab.push_back(gcd(m, n));
         } else{
            gcd_ab.push_back(gcd(n, m));
         }
      }
   }

   int sum = 0;
   for (int x : gcd_ab){
      for (int i=K; i>0; i--){
         int m, n;
         if (i > x){
            m = i;
            n = x;
         }else{
            m = x;
            n = i;
         }
         sum += gcd(m, n);
      }
   }

   cout << sum << endl;

   //for (int i=0; i<gcd_ab.size(); i++)
   //   cout << gcd_ab.at(i) << " " << endl;
}

