#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
using namespace std;
ll n, ans;
inline ll read(){                                     
    ll s = 0, w = 1;
    char ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar()) w *= ch == '-' ? -1 : 1;
    for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
    return s * w;
}
inline ll gcd(ll a, ll b){                              
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}
inline void work(){
    n = read();                                        
    REP(i, 1, n)                                        
        REP(j, 1, n)                                    
            REP(k, 1, n){                                
                if (min(i, min(j, k)) == 1) ans++;      
                else if (i == j && j == k) ans += i;   
                    else ans += gcd(i, gcd(j, k));      
            }
    printf("%lld\n", ans);                            
}
int main(){
    work();
    return 0;
}