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

#define ll long long
#define vec vector<ll>
#define rev(a); reverse(a.begin(), a.end());
#define sorta(a); sort(a.begin(), a.end());
#define sortd(a); sort(a.begin(), a.end(), greater<int>());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)
#define printarray(a) FOR(Q,0,(int)(a).size()) cout<<(a)[Q]<<" "; cout<<'\n';
#define pb push_back
#define mp make_pair

ll MOD = 1000000007;
ll INF = 1LL << 60;

/*****************************************************************************/


int gcd(int a, int b) {
	if (a<b) {
		a^=b;
		b^=a;
		a^=b;
	}
	if (a==b) return a;
	if (b==0) return a;
	return gcd(b,a%b);
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;cin>>n;
	n++;
	ll out=0;

	FOR(i,1,n) {
		FOR(j,1,n) {
			FOR(k,1,n) {
				out+=gcd(i,gcd(j,k));
				out%=MOD;
			}
		}
	}
	cout<<out;
}