#include<stdio.h>

int gcd(int x, int y) {
    if (y == 0)
        return (x);
     else
        return (gcd(y, x % y));
}


int main(void){
    int K,a,b,c;
    unsigned long sum=0;
    scanf("%d",&K);

    for(a=1;a<=K;a++){
        for(b=1;b<=K;b++){
            for(c=1;c<=K;c++){
                sum+=gcd(gcd(a,b),c);
            }
        }
    }

    printf("%lu\n",sum);

    return 0;
}