#include <stdio.h>

int gcd2(int a, int b){
    if(a == b){ return a;}
    else if(a > b){ return gcd2(a-b, b); }
    else{ return gcd2(a, b-a); }
}

int gcd3(int a, int b, int c){
    return gcd2(gcd2(a, b), c);
}

int main(void){
    int K;
    scanf("%d", &K);
    int a, b, c, tmp;
    int ans = 0;
    for(a = 1; a <= K; ++a){
        for(b = a; b <= K; ++b){
            for(c = b; c <= K; ++c){
                tmp = gcd3(a, b, c);
                if(a == b && b == c){}
                else if(a < b && b < c){ tmp *= 6;}
                else{ tmp *= 3; }
                ans += tmp;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}