#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); i++)


int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int gcd3(int a, int b, int c){
    int ab = gcd(a, b);
    return(gcd(ab, c));
}

int main() {
    /*変数定義，入力*/
    int K;
    cin >> K;

    //ll A, B;cin >> A >> B;
    //vector<ll> a(N);  rep(i, N) cin >> a[i];
    
    /*演算*/
    ll sum = 0;

    //3数が等しい
    rep(i, K){
        sum += i + 1;
    }
    //2数が等しい
    rep(i, K){
        rep(j, i){
            sum += gcd3(i + 1, j + 1, j + 1) * 3;
            sum += gcd3(i + 1, i + 1, j + 1) * 3;
        }
    }

    //すべて別の数
    rep(i, K){
        rep(j, i){
            rep(k, j){
                sum += gcd3(i + 1, j + 1, k + 1) * 6;
            }
        }
    }
    
    /*出力*/
    cout << sum << endl;
    /*終了*/
    return 0;
}