#include <iostream>
using namespace std;
int main(void){
    int K,tmp,sum;
  	scanf("%d", &K);
	if(0<K && K<201){
	    for(int ak = 1; ak < K+1; ak++){
	        for(int bk = 1; bk < K+1; bk++){
	            for(int ck = 1; ck < K+1; ck++){
	                int a = ak;
	                int b = bk;
	                int c = ck;
	                  if(a<b){
	                      tmp = a;
	                      a = b;
	                      b = tmp;
	                  }
	                  int ab = a % b;
	                  while(ab!=0){
	                      a = b;
	                      b = ab;
	                      ab = a % b;
	                  }
	                  if(b<c){
	                      tmp = b;
	                      b = c;
	                      c = tmp;
	                  }
	                  int abc = b % c;
	                  while(abc!=0){
	                      ab = c;
	                      c = abc;
	                      abc = ab % c;
	                  }
	                  sum = sum + c;
	            }
	        }
	    }
	    printf("%d", sum);
	}
}