#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

int gcd(int a,int b){
    if(a<b){
        int temp=a;
        a=b;
        b=temp;
    }

    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
        
    }
    return b;
}
int main(){
    int k;
    cin>>k;
    int sum=0;
    for(int i=1;i<k+1;i++){
        for(int j=1;j<k+1;j++){
            int gcd_ab=gcd(i,j);
            for(int l=1;l<k+1;l++){
                sum+=gcd(gcd_ab,l);
            }
            
        }
    }
    cout<<sum;
    return 0;
}