#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#define MAXH 101
#define MAXW 101
#define INF 1000
#define MAXN 100001

int N, M;

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

int gcd(int a, int b, int c){
    return gcd(gcd(a, b), c);
}


int main(){
    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(i, j, k);
            }
        }
    }

    printf("%lld\n", sum);
    
    return 0;
}