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

int gcd(int x, int y){
    int r;

    while((r = x % y) != 0){
        x = y;
        y = r;
    }
    return y;
}

int main(void){
	int k;
	int i,j,l;
	long int ans=0;

	scanf("%d",&k);
	for(i=1;i<=k;i++){
		for(j=1;j<=k;j++){
			for(l=1;l<=k;l++){
				ans=ans+gcd(l,gcd(i,j));
			}
		}
	}
	printf("%ld",ans);
	return 0;
}