import Foundation


    func solveGCD(_ a: Int, _ b: Int) -> Int {
        if a == 0 || b == 0 {
            fatalError("Fount zero value in the arguments")
        }
        var i = a, j = b
        
        if i < j {
            swap(&i, &j) // a < b だとwhile内で処理が a >= b のときより一度だけ多く行われて計算の無駄
         }
        
        while let l: Int = i%j, l != 0 {
            i = j
            j = l
        }
        
        return abs(j) //最小公倍数は常に正の整数とする
    }
    func solveGCD(numbers numbers_: Int...) -> Int {
        if numbers_.count < 2 {
            fatalError("No enough arguments")
        }
        var numbers = numbers_
        while numbers.count != 2 {
            numbers[1] = solveGCD(numbers[0], numbers[1])
            numbers.remove(at: 0)
        }
        return solveGCD(numbers[0], numbers[1])
    }
 
let inputLine: String = readLine()!
 
let k: Int = Int(inputLine)!

let a = 1
let b = 1
let c = 1
 
var ans = 0;

for a in 1...k {
  for b in 1...k {
    for c in 1...k {
      ans += solveGCD(numbers: a, b, c)
    }
  }
}


 
print(ans)
