// Your code here!
func gcd(_ a: Int, _ b: Int) -> Int {
   let r = a % b
   if r != 0 {
       return gcd(b, r)
   } else {
       return b
   }
}
var num = Int(readLine()!)!
var ans:Int = 0
for i in 1...num{
    for j in 1...num{
        for k in 1...num{
        var n:Int = 0
            n += gcd(i,j)
            ans += gcd(k,n)
        }
    }
}
print(ans)