#include <iostream>
using namespace std;
template <class T>
T gcd(T a, T b){
    T m, n, r;
    if(a > b){
        m = a;
        n = b;
    }else{
        m = b;
        n = a;
    }
    
    while(n != 0){
        r = m % n;
        m = n;
        n = r;
    }
    
    return m;
}

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

    long long int res = 0;

    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            int gcd_ab = gcd(i, j);
            for(int l = 1; l <= k; l++){
                res += gcd(gcd_ab, l);
            }
        }
    }

    cout << res << endl;

    return 0;
}