//#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int gcd(int a,int b){
    int tmp,r;
    if(b>a){
        tmp=a;
        a=b;
        b=tmp;
    }

    while ((r=a%b)) {
        a = b;
        b = r;
    }

    return b;
}

int main(){
    int n=0;
    long long ans=0;
    //char s[200];
    //bool flag = false;
    //vector<int> a(N,0);

    cin >> n;

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                ans += gcd(gcd(i+1,j+1),gcd(k+1,j+1));
            }
        }
    }

    cout << ans << endl;
    //cout << ( (flag) ? "Yes" : "No" ) << endl;
}