#include <stdio.h>

int gcd(int a,int b){int r,tmp;if(a < b){tmp = a;a = b;b = tmp;}r = a % b;while(r != 0){a = b;b = r;r = a % b;}return b;}

int main()
{
    int k;
    scanf("%d",&k);

    int a,b,c;
    long long ans = 0;
    for (a = 1; a <= k; a++)
    {
        for (b = 1; b <= k; b++)
        {
            for (c = 1; c <= k; c++)
            {
                ans += gcd(gcd(a,b),c);
            }
        }
    }
    printf("%lld",ans);
}
