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

for a in 1...K {
    for b in a...K {
        for c in b...K {
            if Set([a, b, c]).count == 3 {
                res += gcd(gcd(a, b), c) * 6
            } else if Set([a, b, c]).count == 2 {
                res += gcd(gcd(a, b), c) * 3
            } else {
                res += gcd(gcd(a, b), c)
            }
        }
    }
}
print(res)  // (๑•ૅㅁ•๑)