let k = Int(readLine()!)!

func gcd(_ m: Int, _ n: Int) -> Int {
    var m = m
    var n = n
    var r: Int?
    if n > m {
        (m, n) = (n, m)
    }
    while r != 0 {
        r = m % n
        (m, n) = (n, r!)
    }
    return m
}

var result = 0

for a in 1...k {
    for b in 1...k {
        for c in 1...k {
            result += gcd(a, gcd(b, c))
        }
    }
}

print(result)
