#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <tgmath.h>
#include <time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007
#define nyan(i) for (int i = 1; i <= n; i++)
ll n, sum = 0;

ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}

main()
{
    scanf("%lld", &n);
    nyan(i)
    {
        nyan(j)
        {
            nyan(k)
            {
                sum += gcd(gcd(i, j), k);
            }
        }
    }
    printf("%lld\n", sum);
    return 0;
}