"use strict";
var fs = require("fs");
function main(lines) {
    var number = parseInt(lines[0][0]);
    var numbers = [];
    for (var i = 1; i <= number; i++) {
        numbers.push(i);
    }
    var permutations = [];
    numbers.forEach(function (n1) {
        numbers.forEach(function (n2) {
            numbers.forEach(function (n3) {
                permutations.push([n1, n2, n3]);
            });
        });
    });
    var commonDivisor = function (a, b) { return (b > 0 ? commonDivisor(b, a % b) : a); };
    var greatestCommonDivisor = function (a, b, c) {
        var result = c;
        result = commonDivisor(result, b);
        result = commonDivisor(result, a);
        return result;
    };
    var gcds = permutations.map(function (p) {
        return greatestCommonDivisor(p[0], p[1], p[2]);
    });
    var point = gcds.reduce(function (prev, cur) { return prev + cur; }, 0);
    console.log(point);
}
var lines = fs
    .readFileSync("/dev/stdin", "utf8")
    .split("\n")
    .map(function (l) { return l.split(" "); })
    .filter(function (input) { return !(input.length === 1 && input[0] === ""); });
main(lines);
