import Foundation

func gcd(_ a_: Int, _ b_: Int) -> Int {
    var a = a_
    var b = b_
    while a % b != 0 {
        (a, b) = (b, a%b)
    }
    return b
}

func readInt() -> [Int]{
    return readLine()!.split(separator: " ").map{Int($0)!}
}

func main() {
    let N = Int(readLine()!)!
    var ans = 0
    for i in 1...N {
        for j in 1...N {
            let ij = gcd(i, j)
            for k in 1...N {
                ans += gcd(ij, k)
            }
        }
    }
    
    print(ans)
}

main()
