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

int gcd(int a, int b){
	if(b == 0)
    	return a;
    return gcd(b, a%b);
}

int main(){
	int n, i, j, k, l, s = 0;
	scanf("%d", &n);
    for(i = 1; i <= n; i++){
    	for(j = 1; j <= n; j++){
        	for(k = 1; k <= n; k++){
            	l = gcd(i, j);
                s += gcd(k, l);
            }
        }
    }
    printf("%d\n", s);
    return 0;
}
