#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;

int __gcd(int a,int b){
	if(b==0) return a ;
	return __gcd(b,a%b) ;
}

int g(int a ,int b , int c){
	return __gcd(a,__gcd(b,c)) ;
}	
int add(int a ,int b){
	return a+b ;
}
void solve(){
	int k ;
	cin >> k ;
	int ans  = 0 ;
	for(int i = 1 ; i <= k ; i++){
		for(int j = 1 ; j <= k ; j++){
			for(int b = 1 ; b <= k ; b++){
				ans = add(ans, g(i,j,b)) ;
			}
		}
	}
	cout << ans ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}
