#include<iostream>
//#include<numeric>
#include<algorithm>
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;

typedef long long ll;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main()
{
    int k;
    ll sum=0;
    cin>>k;
    rep(a,k)
    {
        rep(b,k)
        {
            rep(c,k)
            {
                int tmp=gcd(a,b);
                sum+=gcd(tmp,c);
            }
        }
    }
    cout<<sum<<endl;

    return 0;
}