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

let N = Int(readLine()!)!
var sum = 0

for a in 1...N {
    for b in 1...N {
        let ab = gcd(a, b)
        for c in 1...N {
            sum += gcd(ab, c)
        }
    }
}

print(sum)