#include<iostream>
#include<string>

using namespace std;

int func(int a, int b) {
    int tmp,r;
    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;

}

int main()
{
    // スペース区切りの整数の入力
    int K,ab;
    cin >> K;

    long int sum;

    sum = 0;
    for (int i = 1; i < K+1; i++)
    {
        for (int j = 1; j < K+1; j++)
        {
            for (int k = 1; k < K+1; k++)
            {
                ab= func(i,j);
                sum += func(ab,k);
            }
        }
    }

    cout << sum << endl;
    return 0;
}