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