function Main(input){
	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 
}
var sum = 0;
for(var i=1;i<=input;i++){
	for(var j=1;j<=input;j++){
		for(var k=1;k<=input;k++){
			sum += gcd(i,j,k);
		}
	}
}
console.log(sum)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());