#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;

inline int read(){
	re int ans = 0;re bool f = 1;re char ch = getchar();
	while(ch<'0'||ch>'9'){if (ch=='-')f = 0;ch = getchar();}
	while(ch>='0'&&ch<='9'){
		ans = (ans<<3)+(ans<<1)+(ch^48);
		ch = getchar();
	}
	return f?ans:~(ans-1);
}
int mp[256][256];
int ggcd(int a,int b){
	return b==0?a:ggcd(b,a%b);
}
signed main(void){
	for(re int i=1;i<=212;++i){
		for(re int j=1;j<=212;++j){
			mp[i][j] = ggcd(i,j);
		}
	}
	int k = read();
	int ans = 0;
	for(re int i=1;i<=k;++i){
		for(re int j=1;j<=k;++j){
			for(re int h=1;h<=k;++h){
				ans+=mp[i][mp[j][h]];
				/*cout<<mp[i][mp[j][h]]<<' ';*/
				/*cout<<ans<<' ';*/
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}