#include <iostream>
using namespace std;

int gcd(int a,int b){
    if(b>a){
        int t;
        t = a;
        a = b;
        b = t;
    }
    if(a%b==0){
        return b;
    }
    else{
        return(gcd(b,a%b));
    }
}

int main(){
    int k;
    cin>>k;
    int sum = 0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                int a = gcd(i,j);
                sum = sum + gcd(a,l);
            }
        }
    }
    cout<<sum<<endl;
}