#include<stdio.h>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int main(){
  int n,i,j,k,s=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      for(k=1;k<=n;k++)s+=gcd(i,gcd(j,k));
    }
  }
  printf("%d\n",s);
  return 0;
}
