#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
unsigned euclidean_gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
int main(){
  int n;
  cin >> n;
  int ans=0;
  rep(i,n){
    rep(j,n){
      int gcd=euclidean_gcd(i+1,j+1);
      rep(q,n){
        int a=euclidean_gcd(gcd,q+1);
        ans+=a;
      }
    }
  }
  cout << ans << endl;
}