// Slower C++ solution:
//Contains functions for implementing a disjoint set union

#include<bits/stdc++.h>

using namespace std;

//#define num 1000000007

#define num 998244353

#define inf 1000000000000000000ll

#define REP(i,a,n) for(ll i=a;i<n;i++)

#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }

#define vll vector<long long>

#define pi pair <int,int>

#define pll pair<long long, long long>

#define vpii vector< pair <int,int>>

#define vpll vector< pair<long long, long long>>

#define max(a,b) (a>b)?a:b

//#define min(a,b) (a>b)?b:a

#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c

#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c

#define avg(a,b) ((a)+(b))/2

//#define push push_back

//#define pop pop_back

#define mp make_pair

#define sf int flag=0     //Remember semicolon

#define assmin(a,b) if(b<=a) { a=b; }

#define assmax(a,b) if(b>=a) { a=b; }

#define fir first

#define sec second

#define mod(a) ((a)>0)?(a):(-(a))

 

 

typedef long long ll;

 

ll next(ll a, ll n)

{

    return (a==n-1)?0:a+1;

}

ll parent[1000005],size[1000005],  tail[300005];

set<ll> cur_par;

ll n,m,q;

ll pos(ll x,ll y)

{

    return (m*(x-1))+y;

}

void init_parent(ll n)

{

    memset(parent,-1,sizeof(parent[0])*n);

}

void make_set(ll v)

{

    parent[v]=v;

    ::size[v]=1;

    tail[v]=v;

}

ll find_set(ll v)

{

    if(parent[v]==v)

    return v;

    return parent[v]=find_set(parent[v]);

}

void union_sets(ll a,ll b, ll A[])

{

    a=find_set(a);

    b=find_set(b);

    if(a==b)

    return;

    if(::size[a]<::size[b])

    {

        swap(a,b);

    }

    parent[b]=a;

    ::size[a]+=::size[b];

    A[a] = min(A[a], A[b]);

}

ll prev(ll a,ll n)

{

    if(a==0)

    return n-1;

    return a-1;

}

ll nex(ll a,ll n)

{

    if(a==n-1)

    return 0;

    else

    return a+1;

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll k;

    cin>>k;

    ll tot=0;

    REP(i,1,k+1)

    {

        REP(j,1,k+1)

        {

            REP(p,1,k+1)

            {

                ll g= __gcd(i,j);

                g= __gcd(g,p);

                tot+=g;

            }

        }

    }

    cout<<tot<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.872444982839132x):
#include<bits/stdc++.h>

using namespace std;

#define num 1000000007

//#define num 998244353

#define REP(i,a,n) for(ll i=a;i<n;i++)

#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }

#define vll vector<long long>

#define pii pair <int,int>

#define pll pair<long long, long long>

#define vpii vector< pair <int,int>>

#define vpll vector< pair<long long, long long>>

#define max(a,b) ((a>b)?a:b)

#define min(a,b) ((a>b)?b:a)

#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)

#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)

#define avg(a,b) ((a)+(b))/2

#define pb push_back

#define pob pop_back

#define sf int flag=0     //Remember semicolon

#define assmin(a,b) if(b<=a) { a=b; }

#define assmax(a,b) if(b>=a) { a=b; }

#define f first

#define s second

#define fix(f,n) std::fixed<<std::setprecision(n)<<f

#define all(x) x.begin(), x.end()

#define M_PI 3.14159265358979323846

typedef long long ll;

ll mod(ll a, ll b)

{

	if(a%b<0)

	{

		return a%b + b;

	}

	return a%b;

}

 

 

ll mod_exp(ll a, ll b, ll c)

{

	ll res=1;

	a=a%c;

	while(b>0)

	{

		if(b%2==1)

		{

			res=(res*a)%c;

		}

		b/=2;

		a=(a*a)%c;

	}

	return res;

}

ll mymod(ll a,ll b)

{

    return ((a%b)+b)%b;

}

bool prime[200001];

void SieveOfEratosthenes() 

{ 

    memset(prime, true, sizeof(prime)); 

    prime[1]=false;

    for (int p=2; p*p<=200000; p++) 

    { 

        if (prime[p] == true) 

        { 

            for (int i=p*p; i<=200000; i += p) 

                prime[i] = false; 

        } 

    } 

    return;

}

ll powe[200005];

void power()

{

    powe[0]=1;

    REP(i,1,200005)

    {

        powe[i]=mymod(2*powe[i-1],num);

    }

}

ll gcdExtended(ll,ll,ll *,ll *);

ll modInverse(ll a, ll m) 

{ 

    ll x, y; 

    ll g = gcdExtended(a, m, &x, &y); 

        ll res = (x%m + m) % m;

        return res;

} 

ll gcdExtended(ll a, ll b, ll *x, ll *y) 

{ 

    if (a == 0) 

    { 

        *x = 0, *y = 1; 

        return b; 

    } 

    ll x1, y1; 

    ll gcd = gcdExtended(b%a, a, &x1, &y1); 

    *x = y1 - (b/a) * x1; 

    *y = x1; 

    return gcd; 

}

ll n; 

struct node

{

	vll adj;

    ll colour;

};

void dfs(node N[], bool vis[], ll i, ll parent=-1)

{

    vis[i]=true;

    if(parent!=-1)

    {

        N[i].colour = 1 - N[parent].colour;

    }

    for(auto x: N[i].adj)

    {

        if(!vis[x])

        {

            dfs(N,vis,x,i);

        }

    }

}

int main()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    ll n=3,k;

    cin>>k;

    ll dp[k+1];

    ll tot=0;

    for(ll i=k;i>k/2;i--)

    {

        dp[i]=1;

        tot = mymod(tot + i*dp[i], num);

    }

    for(ll i=k/2;i>=1;i--)

    {

        dp[i] = mod_exp((k/i),n,num);

        for(ll j=2*i;j<=k;j+=i)

        {

            dp[i] = mymod(dp[i] - dp[j], num);

        }

        tot=mymod(tot+ i*dp[i], num);

    }

    cout<<tot<<endl;

    return 0;

}