Problem:
Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692

Solution in C (GCC 9.2.1) (judge verdict: Wrong Answer)

#include<stdio.h>
int main(){
long long int sum=0;
  int a[4],j,k,l,min,b[4];
scanf("%d", &k);
  
  for(a[0]=1;a[0]<=k;a[0]++){
    for(a[1]=1;a[1]<=a[0];a[1]++){
      for(a[2]=1;a[2]<=a[1];a[2]++){
      	b[0]=a[0];
      	b[1]=a[1];
      	b[2]=a[2];
      	
        while(1){
            min=b[0];
            l=0;
        	if(min>b[1]){
        		min=b[1];
        		l=1;
        	}
        	if(b[0]%min==0 && b[1]%min==0){
        		break;
        	}
        	else{
        	for(j=0;j<=1;j++){
        		if(j!=l){
        			b[j]=b[j]%min;
        		}
        	}
        		//printf("%d %d %d\n",b[0],b[1],b[2]);
        	}
        }
      	while(1){
            	b[1]=min;
        		l=1;
            	if(min>b[2]){
            		min=b[2];
            		l=2;
            	}
            	if(b[2]%min==0){
            	printf("%d %d %d\n",a[0],a[1],a[2]);
              if(a[0]==a[1]&&a[1]==a[2]){
              sum+=min;
              break;
              }
              if(a[0]!=a[1]&&a[1]==a[2]){
              sum+=3*min;
              break;
              }
              if(a[0]==a[1]&&a[1]!=a[2]){
              sum+=3*min;
              break;
              }
              if(a[0]!=a[1]&&a[1]!=a[2]&&a[0]!=a[2]){
              sum+=6*min;
              break;
              }
            }
        		else{
        			for(j=1;j<=2;j++){
        				if(j!=l){
        					b[j]=b[j]%min;
        				}}}}
        }
      }
    }
	printf("%lld\n",sum);
	return 0;
}