#include <stdio.h>

int minn(int x, int y, int z)
{
    if (x >= y)
    {
        if (y >= z)
        {
            return z;
        }

        if (y <= z)
        {
            return y;
        }
    }

    if (x <= y)
    {
        if (x <= z)
        {
            return x;
        }

        if (x >= z)
        {
            return z;
        }
        
        
    }
    
    
}

int main(void)
{
    unsigned long int answer = 0;
    int K;
    scanf("%d", &K);

    for (int i = 1; i <= K; i++)
    {
        for (int k = 1; k <= K; k++)
        {
            for (int j = 1; j <= K; j++)
            {
                for (int n = minn(i, k, j); n >= 1; n--)
                {
                    if (i%n == 0 && k%n == 0 && j%n == 0)
                    {
                        answer += n;
                        break;
                    }
                    
                }
                
            }
            
        }
        
    }

    printf("%lu", answer);
    
    return 0;
}