#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007
int gcd(int a, int b){
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int k;
    cin>>k;
    ll sum = 0;
    for(int i = 1; i<=k; i++){
        for(int j = 1; j<=k; j++){
            for(int l = 1; l<=k; l++){
                sum+=gcd(gcd(i,j),l);
            }
        }
    }
    cout<<sum<<"\n";
}