#include<stdio.h>

int main(void)
{
	int k,a,b,c,x,y;
	int ca,cb,cc,cx;
	int sum=0;

	scanf("%d",&k);

	for(a=1;a<=k;a++){
		for(b=1;b<=k;b++){
			ca=a;
			cb=b;
			while(x!=0){
				x=ca%cb;
				ca=cb;
				cb=x;
			}
			x=ca;
			for(c=1;c<=k;c++){
				cc=c;
				cx=x;
				while(y!=0){
					y=cc%cx;
					cc=cx;
					cx=y;
				}
				y=cc;
				sum+=y;
			}
		}
	}

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

	return 0;
}
