#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int s;
    s=0;
    for(int i =1;i<=N;i++){
        for(int j =1;j<=N;j++){
            for(int k =1;k<=N;k++){
                s+=__gcd(i,__gcd(j,k));
            }
        }
    }
    cout << s << endl;
}