#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int A,B,C,k,r,tmp,ans=0,a,b,c;
    char token[300]={};
    fgets(token, sizeof(token), stdin);k=atoi(token);
    for (A=1; A<=k; A++) {
        for (B=1; B<=k; B++) {
            for (C=1; C<=k; C++) {
                a=A;b=B;c=C;
                if(a<b){tmp=a;a=b;b=tmp;}
                r=a%b;
                while(r!=0){
                    a = b;
                    b = r;
                    r = a % b;
                }
                if(c<b){tmp=c;c=b;b=tmp;}
                r=c%b;
                while(r!=0){
                    c = b;
                    b = r;
                    r = c % b;
                }
                ans+=b;
            }
        }
    }
    printf("%d",ans);
    return 0;
}


