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

int main() {
    long long int n,tmp,ans=0;cin>>n;
    
    for(long long int i=1;i<=n;++i){
        for(long long int  j=1;j<=n;++j){
            for(long long int  k=1;k<=n;++k){
                tmp=__gcd(i,j);
                tmp=__gcd(tmp,k);
                ans+=tmp;
            }
        }
    }
    cout<<ans<<endl;

	return 0;
}