#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

int gcd(int i, int j) {
    int a = i;
    int b = j;

    int r = a % b;

    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}
 
int main(){
    int N;
    cin >> N;

    long long sum = 0;

    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                sum += gcd(gcd(i,j),k); 
            }
        }
    }

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