func gcd(_ a: Int, _ b: Int) -> Int {
    guard b != 0 else { return a }

    let r = a % b
    if r > b - r {
        return gcd(b, b - r)
    } else {
        return gcd(b, r)
    }
}

func gcd(_ a: Int, _ b: Int, _ c: Int) -> Int {
    gcd(gcd(a, b), c)
}

let N = Int(readLine()!)!

var sum0 = 0
for i in 1 ... N {
    guard i + 1 <= N else { continue }
    for j in i + 1 ... N {
        guard j + 1 <= N else { continue }
        for k in j + 1 ... N {
            sum0 += gcd(i, j, k)
        }
    }
}

var sum1 = 0
for i in 1 ... N {
    guard i + 1 <= N else { continue }
    for j in i + 1 ... N {
        sum1 += gcd(i, i, j)
        sum1 += gcd(i, j, j)
    }
}

var sum2 = 0
for i in 1 ... N {
    sum2 += gcd(i, i, i)
}

print(sum0 * 6 + sum1 * 3 + sum2)
