#include<bits/stdc++.h>
using namespace std;
int main(){
	int a=1,b=1,c=1;
	int i=1;
	int k;
	cin>>k;
	int sum;
	for (a=i; a<=k; a++){
   		for (b=i; b<=k; b++){
      		for (c=i; c<=k; c++){
          		sum+=__gcd(a,__gcd(b,c));
      		}
   		}
	}
	cout<<sum;
}