#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;


template<typename T>
T gcd(T a, T b) {
    if (a%b == 0) return b;
    return gcd(b, a%b);
}


int main(int argc, char **argv) {
    i64 k;
    cin >> k;

    i64 ans{0};

    for (int i=1; i<k+1; ++i) {
        for (int j=1; j<k+1; ++j) {
            int gcdij= gcd<int>(i,j);
            for (int l=1; l<k+1; ++l) {
                ans += gcd<int>(l, gcdij);
            }
        }
    }

    cout << ans <<endl;
    return 0;
}