#include<stdio.h>
int main(){
int k=0;
int sum=0;
int tmp=0;
int r=0;
scanf("%d",&k);
for(int i=1;i<=k;i++){
    for(int j=1;j<=k;k++){
        for(int l=1;l<=k;l++){

  if(i<j){
    tmp = i;
    i = j;
    j = tmp;
  }
 
  r = i % j;
  while(r!=0){
    i = j;
    j = r;
    r = i % j;
  }

  if(l<j){
    tmp = l;
    l = j;
    j = tmp;
  }
 
  r = i % j;
  while(r!=0){
    l = j;
    j = r;
    r = l % j;
  }
sum+=j;
        }
    }
}
printf("%d\n",sum);
return 0;

}