"use strict";
function main(input) {
  const k = parseInt(input[0]);
  let sum = 0;

  function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
  }

  for(let a=1;a<=k;a++){
    for(let b=1;b<=k;b++){
      for(let c=1;c<=k;c++){
        let gcd_now = gcd(gcd(a,b),c);
        sum += gcd_now;
      }
    }
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));