#include<stdio.h>


int  gcd2(int a,int b){

    int bin;
    int sw;
    // switch
    if(a<b){
        a=sw;
        a=b;
        b=sw;
    }

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

    while(a%b!=0){
        bin=a%b;

        if(bin==0){
            break;
        }
        a=b;
        b=bin;
    }

    return b;
}




int main (void){

    int K,a,b,c;
    long long ans=0;
    int ab_gcd;
    int ia,ib,ic;
    int bin;
    int sw=0;

    scanf("%d",&K);

    for(ia=1;ia<=K;ia++){
        for(ib=1;ib<=K;ib++){
            for(ic=1;ic<=K;ic++){

                a=ia;
                b=ib;

                if(a<b) {
                    sw=a;
                    a = b;
                    b = sw;
                }

                while(1){
                    bin=a%b;
                    if(bin==0){
                        break;
                    }

                    a=b;
                    b=bin;
                }

                ab_gcd=b;

                /*-------------*/
                a=ab_gcd;
                b=ic;
                sw=0;
                if(a<b) {
                    sw = a;
                    a = b;
                    b = sw;
                }

                while(a%b!=0){
                    bin=a%b;
                    if(bin==0){

                        break;
                    }
                    a=b;
                    b=bin;
                }
                ans+=b;
            }
        }
    }

    printf("%d",ans);

    return 0;
}