#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define mkpr(x1,x2) make_pair(x1,x2)
typedef long long int ll;

//ll num[50];
//ll num2[50];
//ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<pair<ll,ll>,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
//vector<ll> vll;

ll gcd(ll n,ll m)
{
    if(m==0) return n;
    return gcd(m,n%m);
}

int main(void)
{
    double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            a=gcd(i,j);
            if(a==1) sum+=n;
            else if(a==2)
            {
                sum+=a*(n/2);
                sum+=n-n/2;
            }
            else if(a==3)
            {
                sum+=a*(n/3);
                sum+=n-n/3;

            }
            else
            {
                for(k=1;k<=n;k++)
                    sum+=gcd(a,k);
            }
        }
    }
    cout<<sum;
    return 0;
}



