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

int gcd( int x, int y )
{
    return (x % y)? gcd(y, x % y): y;
}
int main()
{
    int k;
    cin >> k;
    ll sum = 0;
    for( int a = 1; a <= k; a++ ){
        for( int b = 1; b <= k; b++ ){
            for( int c = 1; c <= k; c++ ){
                int gcd_1 = gcd( a, b );
                int gcd_2 = gcd( c, gcd_1 );
                sum = sum + gcd_2;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

