#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>


using namespace std;


int gcd2(int a,int b){
  if(b==0)return a;
  else return gcd2(b,a%b);
}

int gcd(int a,int b,int c){
  return gcd2(gcd2(a,b),c);
}

  
int main() {
  int k;
  cin>>k;
  int ans = 0;
  for(int i = 1;i<=k;i++){
    for(int j = 1;j<=k;j++){
      for(int t = 1;t<=k;t++){
	ans += gcd(i,j,t);
      }
    }
  }
    cout<<ans<<endl;
  return 0;
}