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

int gojoho(int a,int b){
    while(1){
        int r=a%b;
        if(r==0)
            return b;
        else{
            a=b;
            b=r;
        }
    }
}

int main() {
    int l;
    int tmp;
    int sum=0;
    cin >> l;
    for (int i=1;i<=l;i++){
        for(int j=1;j<=l;j++){
            for (int k=1;k<=l;k++){
                tmp = gojoho(i,j);
                tmp = gojoho(tmp,k);
                sum+=tmp;
            }
        }
    }
    cout << sum << endl;
    // int test =gojoho(2,3);
    // cout << test << endl;
    return 0;
}

