#include<iostream>
#include<string>

using namespace std;

int gcd(int a, int b);

int main(){
    int k;
    cin >> k;
    int sum = 0;
    for (int a = 1; a <= k; a++){
        for (int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                sum += gcd(a, gcd(b, c));
            }
        }
    }

    cout << sum << endl;
    return 0;
}

int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}