#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#define ll long long int

int gcd(int a,int b){int r,tmp;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;
    scanf("%d",&K);

    int sum1=0;
   int i=1;
   int j=1;
   int d=1;
        while (d<=K)
        {
         sum1+=gcd(gcd(d,j),i);
         if (i<K)i++;

         else if (i>=K && j<=K)j++;
         else if (j>=K)d++;

        }
   i=1;
   j=1;
   d=1;

   while (d<=K)
        {
         sum1+=gcd(gcd(i,j),d);
         if (i<K)i++;

         else if (i>=K && j<=K)j++;
         else if (j>=K)d++;

        }
        sum1--;
        sum1-=gcd(gcd(K,K),K);
   i=1;
   j=1;
   d=1;
     while (i<=K)
        {
         sum1+=gcd(gcd(j,i),d);
          i++;
        }
        sum1--;


   i=2;
   j=2;
   d=1;
        while (j<=K)
        {
         sum1+=gcd(gcd(i,d),j);
         if (i<K)i++;

         else if (i>=K && j<=K)j++;

        }

      printf("%d",sum1);


    return 0;

}
