import std.algorithm;
import std.array;
import std.conv;
import std.numeric;
import std.stdio;
import std.string;

void main()
{
    long n;
    long sum;
    
    n = readln.chomp.to!(long);
    
    sum = 0;
    
    for (long i = 1; i <= n; i++) {
        for (long j = 1; j <= n; j++) {
            for (long k = 1; k <= n; k++) {
                sum += gcd(i, gcd(j, k));
            }
        }
    }
    
    writeln(sum);
}
