#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int gcd(int a, int b) {
    if (a < b) {
        return gcd(b, a);
    }
    if (a % b == 0) {
        return b;
    }
    return gcd(b, a%b);
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int K;
    cin >> K;
    
    ll Sum = 0;
    for (int a = 1; a <= K; ++a) {
        for (int b = 1; b <= K; ++b) {
            int Temp = gcd(a, b);
            for (int c = 1; c <= K; ++c) {
                Sum += gcd(Temp, c);
            }
        }
    }
    cout << Sum << endl;

    return 0;
}
