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

int main()
{
    int a=1,b=1,c=1,sum=0,hcf,st,k;
    scanf("%d",&k);
    for(a=1;a<=k;a++){
        for(b=1;b<=k;b++)
        {
            for(c=1;c<=k;c++){
        st=a<b?(a<c?a:c):(b<c?b:c);
        for(hcf=st;hcf>=1;hcf--)
    {
        if(a%hcf==0 && b%hcf==0 && c%hcf==0)
            break;
    }
        sum=sum+hcf;

            }
        }
    }
    printf("%d\n",sum);


    return 0;
}
