/*
 * Coder: @SumitRaut
 */
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#define ll long long
#define debug1(x) fprintf(stderr, #x "--> %d\n", x);
#define debug2(x,y) fprintf(stderr, #x "--> %d  " #y "--> %d\n", x,y);
#define dprintarr(x,n,arr) for(i=x;i<n;++i) {fprintf(stderr,"%d ",arr[i]);} fprintf(stderr,"\n");
#define scanarr(x,n,arr) for(i=x;i<n;++i) {scanf("%d ",&arr[i]);}
#define printarr(x,n,arr) for(i=x;i<n;++i) {printf("%d ",arr[i]);}printf("\n");
ll mod=1e9+7;
#ifndef ONLINE_JUDGE
#define getchar_unlocked getchar
#endif
int scan() {
    register int vl = 0;
    char c;
    bool ng = 0;
    c = getchar_unlocked();
    if (c == '-')
        ng = 1;
    while (c < '0' || c > '9') c = getchar_unlocked();
    while (c >= '0' && c <= '9') {
        vl = (vl << 3) + (vl << 1) + c - '0';
        c = getchar_unlocked();
    }
    if (ng)
        vl = -vl;
 
    return vl;
}

int gcdsh(int x,int y) { /* return y==0?x:gcd(y,x%y); */ while(x && y) { x%=y; if(x) y%=x; } return x+y; }
int main()
{
	int k=scan()+1,ans=0;
	for(int i=1;i<k;++i) {
		for(int j=1;j<k;++j) {
			for(int l=1;l<k;++l) {
				ans+=gcdsh(gcdsh(i,j),l);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}
