#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}

int main(void) {

    int k; cin >> k;
    ll sum = 0;
    for(int i = 1; i <= k; i++) {
        for(int j = 1; j <= k; j++) {
            for(int l = 1; l <= k; l++) {
                sum += gcd(i, gcd(j, l));
            }
        }
    }

    cout << sum << endl;


    return 0;
}