#include <bits/stdc++.h>
#define ll long long
#define intm INT_MAX
#define llm LLONG_MAX

using namespace std;
int MOD = 998244353;

int ar[250][250];
int gcd(int a,int b){
    if( ar[a][b] != 0 ) return ar[a][b];
    //assume a <= b
    if( b < a ) swap(a,b);
    if( a == 0 ) return ar[a][b] = b;
    return ar[a][b] = gcd( b%a, a );
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int N;
	cin >> N;
	ll ans = 0;
	for(int i = 1; i <= N; i++){
        for(int j=1; j <= N; j++){
            for(int k=1; k <= N; k++){
                ans += gcd(i, gcd(j,k) );
            }
        }
	}
    cout << ans;




}
