#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define MOD 1000000007

int min(int a, int b) {
    return a<b?a:b;
}

int max(int a, int b) {
    return a>b?a:b;
}

int compare(const void* a, const void* b) {
    return (*(int*)a - *(int*)b);
}

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

int main() {
    int n, i, j, k;
    long long int sum = 0;
    if(scanf("%d", &n)) {
        for(i=1;i<=n;i++) {
            for(j=1;j<=n;j++) {
                for(k=1;k<=n;k++) {
                    if(i == 1 || j == 1 || k == 1)
                        sum += 1;
                    else
                        sum += gcd(i, gcd(j, k));
                }
            }
        }
        printf("%lld", sum);
    }
    return 0;
}