        #include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
 
        bool check(int n,int k){
            while(n%k==0){
                n=n/k;
            }
            return n%k==1;
        }
        
        signed main() {
 
 
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n;
        cin>>n;
        int ans=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                for(int k=1;k<=n;k++){
                    int t=__gcd(i,j);
                    t=__gcd(t,k);
                    ans+=t;
                }
            }
        }
        cout<<ans;
 
 
        return 0;
    }