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

int gcd(int x, int y);

int main()
{
    int a, b, c, N;
    int sum=0;
    
    scanf("%d", &N);

    for(c=1;c<=N;c++){
    	for(b=1;b<=N;b++){
    		for(a=1;a<=N;a++){
    			sum += gcd(gcd(a,b),c);
    		}
    	}
    }
    
    printf("%d", sum);

    return 0;
}


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

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