#include <bits/stdc++.h>
using namespace std;

int main() {
int K;
cin>>K;	
int answer=0;
for(int a=1; a<K+1; a++){
for(int b=1; b<K+1; b++){
for(int c=1; c<K+1; c++){
answer+=gcd(a,b,c);
}
}
}
cout<<answer<<endl;
}