#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int r,tmp;
int main () {
	
	int K;
	scanf("%d",&K);
	
	int answer =0;
	
	for(int i=1;i<=K;i++) {
		for(int j=1;j<=K;j++) {
			int a=i;int b=j;
			if(a<b){
				tmp = a;
				a=b;
				b=tmp;
			}
			r=a%b;
			while(r!=0){
				a=b;b=r;
				r=a%b;
			}
			
			for(int k=1;k<=K;k++) {
				int a=b;int b=k;
				if(a<b){
					tmp = a;
					a=b;
					b=tmp;
				}
				r=a%b;
				while(r!=0){
					a=b;b=r;
					r=a%b;
				}
				
  				answer += b;
  			}
  		}
  	}
  printf("%d",answer);
	
	return 0;
}