#include <bits/stdc++.h>  
using namespace std;  
typedef long long ll; 
typedef long double ld; 
const int INF = 0x3f3f3f3f;  
const int N = 200000 + 5;
int gcd(int a,int b){
	return b == 0?a:gcd(b,a%b);
}
int main()
{
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			int z = gcd(i,j);
			for(int k = 1; k <= n; k++){
				sum += gcd(z,k);
			}
		}
	}
	cout << sum << endl;
    return 0;
}