open System

let rec _gcd a b = if a % b = 0 then b else _gcd b (a % b)

let gcd a b c = _gcd a b |> _gcd c

[<EntryPoint>]
let main argv =
    let K = Console.ReadLine() |> int
    let ans = seq {
        for a in 1 .. K do
            for b in 1 .. K do
                for c in 1 .. K -> gcd a b c
    }
    ans |> Seq.sum |> printfn "%d"
    0
