#include<iostream>
using namespace std;

int euclidean(int i, int j){
    int a, b, r;

    if(i >= j){
        a = i;
        b = j;
    }
    else{
        a = j;
        b = i;
    }
    
    while(1){
        if(a % b == 0) break;
        r = a % b;
        a = b;
        b = r;
    }
    
    return b;
}

int main(void){
    int K, e;
    long sum;
    
    cin >> K;
    
    sum = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            e = euclidean(i, j);
            for(int k = 1; k <= K; k++){
                sum += euclidean(k, e);
            }
        }
    }
    
    cout << sum << endl;
    return 0;
}