#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define irp(i,s,e) for(int i=(s);i>(e);--i)
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
// #define NMAX 1000000000
ll K;

ll solve(){
	ll ans = 0;
	rp(a,1,K+1){
		rp(b,1,K+1){
			rp(c,1,K+1){
				ll g = gcd(a,b);
				g = gcd(g,c);
				ans += g;
			}
		}
	}
	return ans;
}

int main(){
	cin>>K;
	cout<< solve() <<endl;
}
