#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int getgcd(int n, int m){
    int r;
    if(n > m){
        int t = m;
        m = n;
        n = t;
    }
    while((r = m % n) != 0){
        m = n;
        n = r;
    }
    return n;
}



int main(){
    int k;
    long ans = 0;
    cin >> k;
    for(int i=1; i <= k; ++i){ 
        for(int j=1; j <= k; ++j){
            for(int l=1; l <= k; ++l){
                ans = ans + getgcd(getgcd(i,j),l);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}