// 🐋💭
import Foundation

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

func intGcd(_ a: Int, _ b: Int) -> Int {
    let r = a % b
    if r != 0 {
        return intGcd(b, r)
    } else {
        return b
    }
    
}


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

