#include <stdio.h>
 
int main(){
    int n,i,k1,k2,z;
    int sum=0,temp;
    scanf("%d",&n);
    for(int a=1;a<=n;a++){
     for(int b=1;b<=n;b++){
         for(int c=1;c<=n;c++){
             if(b>c){
                 temp=c;
                 c=b;
                 b=temp;
             }
             while( c % b != 0 )
             {
               i = c % b;
               c = b;
               b = i;
             }
           k1=b;
          }
          if(k1>a){
                 temp=a;
                 a=k1;
                 k1=temp;
             }
     while( a % k1 != 0 )
         {
          z = a % k1;
          a = k1;
          k1 = z;
         }
         k2=k1; 
     }sum=sum+k2;
    }
    printf("%d",sum);
    
    return 0;
}    