#include<iostream>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll=long long;
const ll INF=1LL<<60;


int main(){
  ll k,sum=0;
  cin>>k;
  auto gcd=[&](int a,int b){
    int tmp=a%b;
    while(tmp!=0){
      a=b;
      b=tmp;
      tmp=a%b;
    }
    return b;
  };
  for(int a=1;a<=k;a++){
    for(int b=1;b<=k;b++){
      for(int c=1;c<=k;c++){
	int x=gcd(max(a,b),min(a,b));
	int y=gcd(max(b,c),min(b,c));
	sum+=gcd(max(x,y),min(x,y));
      }
    }
  }
  cout << sum;
}




