"use strict"
// input data
function main(input) {
    let k = Number(input.split('\n')[0].split(' ')[0]);
    let sum = 0;
    for (let i = 1; i <= k; i++) {
        for (let n = 1; n <= k; n++) {
            for (let j = 1; j <= k; j++) {
                sum += gcd(i, n, j);
            }  
        }
    }
    console.log(sum);
}

function gcd() {
    var f = (a, b) => b ? f(b, a % b) : a
    var ans = arguments[0]
    for (var i = 1; i < arguments.length; i++) {
        ans = f(ans, arguments[i]); 
    }
    return ans 
}

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