#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int gcd(int x, int y)
{
    int r;
    while((r = x % y) != 0) 
    {
        x = y;
        y = r;
    }
    return y;
}

int main(){
    int n;
    scanf("%d",&n);
    int sum=0;
    F(i,1,n+1){
        F(j,1,n+1){
            F(k,1,n+1){
                sum+=gcd(gcd(i,j),gcd(j,k));
            }
        }
    }
    printf("%d",sum);

    return 0;
}