#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
LL K;
LL gcd (int a,int b){
	if(a<b)return gcd(b,a);
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}

int main(){
	cin>>K;
	LL ans=0;
	REP(i,K){
		REP(j,K){
			REP(k,K){
				LL a=gcd(i+1,j+1);
				ans+=gcd(a,k+1);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}