#include <iostream>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)

  int gcd(int a, int b){
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
  }

int main() {
  int k;
  cin>>k;
  long long int ans=0;
  
  rep(i,1,k+1){
    rep(j,1,k+1){
      rep(l,1,k+1){
        int x=0;
        x=gcd(j,l);
        ans+=gcd(x,i);
        //cout<<i<<j<<l<<endl;
        //cout<<x<<endl;
      }
    }
  }

  cout<<ans<<endl;
  
  return 0;
}