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

int main() {
  int N,a,b,c;
  unsigned long s=0;
  cin >> N;

  for(a=1;a<=N;a++){
    for(b=1;b<=N;b++){
      for(c=1;c<=N;c++){
        s=s+gcd(gcd(a,b),c);
      }
    }
  }
  cout << s << endl;
}