"use strict";

const gcd = (a, b) => {
    if (b > a)
        return gcd(b, a);
    if (b === 0)
        return a;
    return gcd(b, (a % b));
}

const main = (input) => {
    const spi = input.split('\n');
    const k = Number(spi[0]);

    let ans = 0;
    for (let a = 1; a <= k; a++) {
        for (let b = 1; b <= k; b++) {
            let x = gcd(a, b);
            for (let c = 1; c <= k; c++) {
                ans += gcd(x, c);
            }
        }
    }

    console.log(ans);
};

main(require("fs").readFileSync("/dev/stdin", "utf8"));
