#include <iostream>
#include<bits/stdc++.h>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

typedef long long ll;

int gcd(int a,int b){
    int dividend = max(a,b);
    int divider = min(a,b);
    
    if (divider == 0) return dividend;

    while (dividend % divider != 0){
        int r = dividend % divider;
        dividend = divider;
        divider = r;
    }
    return divider ;


}

int main(){
    int k;
    cin >> k;
    ll count = 0;
    int num_gcd;
    rep(a,k){
        rep(b,k){
            rep(c,k){
                num_gcd = gcd(a+1,b+1);
                num_gcd = gcd(num_gcd,c+1);
                count += num_gcd;
            }

        }
    }
    cout << count << endl;

    return 0;
}
