/**
*    author:  Dooloper
*    created: 12.04.2020 20:51:07
**/

#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;
typedef unsigned long ll;

ll GCD(int a, int b, int c){
    return __gcd(__gcd(a,b),c);
    // else return __gcd(__gc?d(a,b),c)*k;
}

int main() {
   cin.tie(0);
   int K;cin>>K;

   ll sum = 0;

    // sum += 1;
   int a = 1;
   int b = 1;
   int c = 1;


   for(; a != K || b != K || c != K ;){
    //    sum += __gcd(__gcd(a,b),c);
    // cout<<111111<<endl;
    //    cout<<a<<" "<<b<<" "<<c<<endl; 
        sum += GCD(a,b,c);
       c++;
       if(c > K) {
           c = 1;
           b ++;
           if( b > K){
               b = 1;
               a++;
           }
       }
   }
//    cout<<a<<" "<<b<<" "<<c<<endl;
    sum += GCD(K,K,K);
   cout<<sum <<endl;
   return 0;
}
