#include<stdio.h>
#include<stdlib.h>
#define ll long long
int gcd(int a,int b){
    int r = a % b;
    while(r > 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int  main(){
    int k;
    scanf("%d",&k);
    int ans = 0;
    for(int i = 1; i <= k; i++)
        for(int j = 1; j <= k; j++)
            for(int l = 1; l <= k; l++)
                ans += gcd(i, gcd(j, l));
    printf("%d\n",ans);
    return 0;
}