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

int main() {
    int n;
    cin >> n;
    
    int res = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = i; j <= n; ++j){
            for(int k = j; k <= n; ++k){
                int x = __gcd(__gcd(i, j), k);
                if(i == j){
                    if(i == k){
                        res += x;
                    }else{
                        res += (3 * x);
                    }
                }else{
                    if(j == k){
                        res += (3 * x); 
                    }else{
                        res += (6 * x);
                    }
                }
            }
        }
    }
    
    cout << res << endl;
    return 0;
}