#include <iostream>

#define rep(i, n) for (int i = 1; i < (int)(n); i++)

using namespace std;

int main () {
    int k = 0;
    cin >> k;

    int max = k + 1 ;
    long total = 0;
    rep(i, max) {
        rep(j, max) {
            rep(k, max) {
                int tmp_a = i;
                int tmp_b = j;
                int tmp_c = k;
                int mod;
                while ( (mod = tmp_a % tmp_b) != 0 ) {
                    tmp_a = tmp_b;
                    tmp_b = mod;
                }

                while ( (mod = tmp_b % tmp_c) != 0 ) {
                    tmp_b = tmp_c;
                    tmp_c = mod;
                }

                total += tmp_c;
            }
        }
    }

    cout << total << endl;

}
