#include <stdio.h>
#include <stdlib.h>

int getgcd(int n, int m)
{
    int r;
    if (n > m)
    {
        int t = m;
        m = n;
        n = t;
    }
    while ((r = m % n) != 0)
    {
        m = n;
        n = r;
    }
    return n;
}


int main()
{
    
    int x;
    scanf("%d", &x);
    int gcd;
    int i;
    int j;
    int k;
    
    int sum = 0;

    for (i = 1; i <= x; i++)
    {
        for (j = 1; j <= x; j++)
        {

            for (k = 1; k <= x; k++)
            {

                gcd = getgcd(getgcd(i, j), k);
                sum+=gcd;
            }
        }
    }

    printf("%d", sum);

    printf("\n");
}