#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
static const int MAXN = 100000;
static const int MAX = 1000000000;

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

int main(){
    int K;
    cin >> K;

    ll ans = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            int a = gcd(i,j);
            for(int k = 1; k <= K; k++){
                ans += gcd(k,a);
            }
        }
    }
    cout << ans << endl;

    return 0;
}