import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

void main() {
    auto N = readln.chomp.to!int;
    long ans = 0;
    foreach (i; 1..N+1) foreach (j; 1..N+1) foreach(k; 1..N+1) {
        ans += gcd(gcd(i, j), k);
    }

    ans.writeln;
}