func gcd(_ x: Int, _ y: Int) -> Int {
    if y == 0 { return x }
    return gcd(y, x % y)
}

let K = Int(readLine()!)!
var res: Int = 0

for a in 1...K {
    for b in 1...K {
        for c in 1...K {
            res += gcd(gcd(a, b), c)
        }
    }
}
print(res)