#include <bits/stdc++.h>
#define int long long int
using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    //cout<<"I must do it...Yeahhh";
    
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int sum=0;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                for(int k=1;k<=n;k++)
                    sum+=__gcd(i,__gcd(j,k));
        cout<<sum;
    }
    //cerr<<"[Execution : "<<(1.0*clock())/CLOCKS_PER_SEC<<"s]\n";
    return 0;
}