'use strict';

const inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');

const input = parseInt(inputs[0], 10);


const results = [];

for (let i = 1 ; i <= input ; ++i) {
  for (let j = 1 ; j <= input ; ++j) {
    for (let k = 1 ; k <= input ; ++k) {
      results.push(gcd(gcd(i, j), k));
    }
  }
}

console.log(results.reduce((acc, cur) => acc + cur, 0));

function gcd(a, b) {
  const max = Math.max(a, b);
  const min = Math.min(a, b);

  const result = a % b;

  if (result === 0) {
    return b;
  }

  return gcd(b, result);
}