#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for(register int i = a;i <= b; ++i)

const int N = 5e6+10, B1=37,P1=19260817,B2=137,P2=998244353;
int n,ans;
int gcd(int a,int b) {if(a>b)a^=b^=a^=b;return a?gcd(b%a,a):b;}
int main() {
	cin>>n;
	f(i,1,n) f(j,1,n) f(k,1,n) ans+=gcd(i,gcd(j,k));
	cout<<ans;
}