#include <stdio.h>

  int gcd(int a,int b){
    while(b!=0){
      int r = a%b;
      a = b;
      b = r;
    }
    return a;
  }
  

int main (){
  int K;
  scanf("%d",&K);
  int ans =0;
  
  for (int i=1;i<=K;i++){
    for (int b=1;b<=K;b++){
      for (int c=1;c<=K;c++){
        ans+=gcd(gcd(i,b),c);
      }
    }
  }
  printf("%d",ans);
  return 0:
}
  