#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,sum=0,i,i1,i2;
    cin>>n;
    for (i=1;i<=n;i++){
        for (i1=1;i1<=n;i1++){
            for (i2=1;i2<=n;i2++){
                sum+=__gcd(i,__gcd(i1,i2));
            }
        }
    }
    cout<<sum<<'\n';
}