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

#define max(a,b) ((a)>(b))?(a):(b)
#define min(a,b) ((a)>(b))?(b):(a)

typedef long long ll;
typedef unsigned long long ull;

int gcd(int a, int b) {
    static int note[201][201] = { 0 };
    if (a % b)
    {
        if (note[a][b] || note[b][a])
        {
            return note[a][b];
        }
        int r = gcd(b, a % b);
        note[a][b] = note[b][a] = r;
        return r;
    }
    return b;
}

int main(void)
{
    int k, sum = 0;
    scanf("%d", &k);
    for (size_t i = 1; i <= k; i++)
    {
        for (size_t j = 1; j <= k; j++)
        {
            for (size_t l = 1; l <= k; l++)
            {
                sum += gcd(gcd(j, l),i);
            }
        }
    }
    printf("%d", sum);
}