#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define pi pair<int,int>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ;
	int k  ;
	cin>> k  ;
   ll ans = 0 ; 
     for(int i = 1 ; i <= k ; ++i){
		 for(int j = 1; j <=  k ; ++j){
			 for(int x = 1  ; x <= k ; ++x){
				 ans = ans + __gcd(i , __gcd(j , x)) ; 
        }
	}
  }
  cout<<ans<<endl;
     
}
