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

int main(){
    int K,count = 0;
    cin >> K;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for (int k = 1; k <= K; k++){
                count += __gcd(i,__gcd(j,k));
            }
        }
    }
    cout << count << endl;
}