#include<iostream>
#include<algorithm>
#include "ソース.h"
using namespace std;
int gcd(int a, int b) {
    int kouyaku = 1;
    for (int i =1; i <= a; i++) {
        if (a % i == 0 && b % i == 0) {
            kouyaku = i;
        }
    }
    return kouyaku;
}

int main() {
    long long k, sum = 1;
    cin >> k;

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

    cout << sum << endl;
}