#include <stdio.h>
#define rep(i, n) for(int i=1; i<(int)(n);i++)

int main(){
  int a, b, c, k, ans=0;
  int gcd_3(int ,int ,int );
  scanf("%d",&k);
  rep(a,k+1){
    rep(b,k+1){
      rep(c,k+1){
        ans += gcd_3(a,b,c);
      }
    }
  }
  printf("%d",ans);
}


int gcd_3(int a,int b,int c){
  int gcd(int ,int );
  return gcd(gcd(a,b),c);
}
int gcd(int a, int b) { return b?gcd(b,a%b):a;}
