#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  int r;
  while(b>0){
    r=a%b;
    a=b;
    b=r;
  }
  return a;
} 
int main() {
  int n;
  cin >> n;
  int i,j,k;
  int sum=0;
  for(i=1;i<n+1;i++){
    for(j=1;j<n+1;j++){
      for(k=1;k<n+1;k++){
        sum+=gcd(j,gcd(i,k));
        
      }
    }
  }
  cout << sum;
}
        
  
        
  