#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int K; cin>>K;
	ll ret=0;
	for (int a=1; a<=K; a++)
		for (int b=1; b<=K; b++)
			for (int c=1; c<=K; c++)
				ret+=__gcd(a,__gcd(b,c));
	cout<<ret<<"\n";
	return 0;
}