#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
    ll M = max(a,b);
    ll m = min(a,b);
    if (m == 0) {
        return M;
    }
    else {
        return gcd(m,M%m);
    }
} 
int main() {
    ll ret = 0;
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++){
       for (int j = 1; j <= n; j++){
           for (int k = 1; k <= n; k++) {
               ll temp = gcd(i,j);
               ret += gcd(temp,k);
           }
       }
    }
    cout << ret;
    return 0;
}