function main(input) {
  var count = 0
  for(int i = 1;i <= input;i++){
    for(int j = 1;j <= input;j++){
     for(int k = 1;k <= input;k++){
        count+=gcd(i,j,k);   
  }
  }
  }
      console.log(count);
}

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 
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));