#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;


// ユークリッドの互除法を用いて再帰関数を書けばよい。
ll my_gcd(int & a, int & b) {
    if (b == 0) return a;
    int temp = a % b;
    return my_gcd(b, temp);
}



int main() {
    int K;
    cin >> K;

    ll res = 0;
    vector<vector<int>> gcd_memo(203, vector<int>(203, -1));
    int temp = 0;
    int temp2 = 0;

    for(int i=1; i<=K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                if (gcd_memo.at(i).at(j) != -1) {
                    temp = gcd_memo.at(i).at(j);
                }
                else {
                    temp = my_gcd(i, j);
                    gcd_memo.at(i).at(j) = temp;
                    gcd_memo.at(j).at(i) = temp;
                }

                if (gcd_memo.at(temp).at(k) != -1) {
                    temp2 = gcd_memo.at(temp).at(k);
                }
                else {
                    temp2 = my_gcd(temp, k);
                    gcd_memo.at(temp).at(k) = temp2;
                    gcd_memo.at(k).at(temp) = temp2;
                }
                
                res += temp2;
            }
        }
    }

    cout << res << endl;

}