#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);


int main(){
    IOS;
    ll n;cin>>n;
    ll sum=0;
    f(i,1,n+1){
        f(j,1,n+1){
            ll gc=__gcd(i,j);
           // cout<<"gc"<<gc<<endl;
            f(k,1,n+1){
                ll x=__gcd(gc,k);
                //cout<<i<<" "<<j<<" "<<k<<" "<<x<<"\n";
                sum+=x;
            }
        }
    }
    cout<<sum;
    return 0;  
} 



