#include <stdio.h>

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

int main(){
    int K, ans=0;
    int M[200][200] = {0};
    int t,i,j,k;
    scanf("%d", &K);
    for(i=1; i<=K; i++){
        ans += i;
        for(j=i+1; j<=K; j++){
            ans += gcd(i,j) * 6;
            for(k=j+1; k<=K; k++){
                ans += gcd(gcd(i,j), k) * 6;
            }
        }
    }
    printf("%d\n", ans);
}