#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int (i) = 0; (i) <(int)n; ++(i))
#define rep2(i,s,n) for(int (i) = (s); (i) <(int)(n); ++(i))

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main() {
    int k;
    cin >>  k;
    ll total = 0;

    rep2(a,1,k+1){ rep2(b,1,k+1) {rep2(c,1,k+1){
       // cout << "e";
        int tmp = gcd(a,b);
        total += gcd(tmp,c);
    }}}

    

    cout << total;

    
}