#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int gcd(int a,int b){
    int g;

    while(a!=b){
        if(a>b){
            a-=b;
        }
        else{
            b-=a;
        }
    }

    return a;
    
}

int main(){
    int n;
    int i,j,k;//preparation for
    int64_t s;

    cin>>n;
    s=0;

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

    cout<<s;
    
    return 0;
}