#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;


ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
    int k;
    cin >> k;
    int ans = 0;
    for(int a = 1; a <= k; ++a) {
        for(int b = 1; b <= k; ++b) {
            for(int c = 1; c <= k; ++c) {
                int temp = gcd(b,c);
                temp = gcd(temp, a);
                ans += temp;
            }
        }
    }
    cout << ans << endl;
    return 0;
}