"use strict";
const gcd = function(a,b){
    if(a % b == 0) return b
    return gcd(b, a % b)
}

const helper = function (a, b, c) {
    let one = gcd(a, b)
    let two = gcd(one, c)
    return two
}

const main = arg => {
    const input = arg.trim().split("\n");
    const K = parseInt(input[0]);
    let res = 0
    for (let a = 1; a <= K; a++) {
        for (let b = 1; b <= K; b++) {
            for (let c = 1; c <= K; c++) {
                res = res + helper(a, b, c)
            }
        }
    }
    console.log(res)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  