#include <bits/stdc++.h>
using namespace std;

int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}

int gcd_3(int x, int y, int z){
  return gcd(gcd(x,y),z);
}

int main() {
  
  int k; cin >> k;
  
  int ans = 0;
  for(int a=1; a<=k; a++){
    for(int b=a; b<=k; b++){
      for(int c=b; c<=k; c++){
        
        if(a==b && b==c) ans += gcd_3(a,b,c);
        else if(a != b && b != c) ans += 6 * gcd_3(a,b,c);
        else ans += 3 * gcd_3(a,b,c);
        
      }
    }
  }
  
  cout << ans << endl;
}
