#include <stdio.h>
 
int main(){
    int n,i,k[1000][1000],x,y,z,c1,c2;
    int sum=0,temp;
    scanf("%d",&n);
    
     for(int b=1;b<=n;b++){
         for(int c=1;c<=n;c++){
             x=b;y=c;
             if(x>y){
                 temp=x;
                 x=y;
                 y=temp;
             }
             while( y % x != 0 )
             {
               i = y % x;
               y = x;
               x = i;
             }
           k[b-1][c-1]=x;
          }}

for(int a=1;a<=n;a++){
    x=a;
    for(c1=0;c1<n;c1++){
        for(c2=0;c2<n;c2++){
          if(k[c1][c2]>x){
                 temp=x;
                 x=k[c1][c2];
                 k[c1][c2]=temp;
             }
     while( x % k[c1][c2] != 0 )
         {
          z = x % k[c1][c2];
          x = k[c1][c2];
          k[c1][c2] = z;
         }sum=sum+k[c1][c2];
        }}
    }
    printf("%d",sum);
    
    return 0;
}    