import std;

void main()
{
  const K = readln().chomp().to!ulong();
  
  ulong sum = 0;
  foreach (i; 1 .. K + 1)
  foreach (j; 1 .. K + 1)
  foreach (k; 1 .. K + 1)
  {
    sum += gcd(gcd(i, j), k);
  }
  
  writeln(sum);
}
