-module('Main').
-export([main/1]).

gcd(A, 0) -> A;
gcd(A, B) -> gcd(B, A rem B).

solve() ->
    [K] = input("~d"),
    Sum = lists:sum([gcd(gcd(A, B), C) || A <- lists:seq(1, K), B <- lists:seq(1, K), C <- lists:seq(1, K)]),
    io:format("~B~n", [Sum]),
    ok.

main(_) ->
    solve(),
    halt().

input(Pat) ->
    {ok, L} = io:fread("", Pat),
    L.
