#include <stdio.h>
int koyakusu(int a, int b);
int sgm(int c);
int main(void)
{
    int x;
    scanf("%d",&x);
    sgm(x);
    return 0;
   
    
    
}
int koyakusu(int a, int b){
    int r=1;
    while(r!=0){
        r = a%b;
        a = b;
        b = r;
    }
    return a;
}

int sgm(int c){
    int a = 0;
    int d = 0;
    int e = 0;
    int i = 1;
    int k = 1;
    int j = 1;
    int so;
    int b = 1;
    int result = 0;
    so = c*c*c;
    for(so = c*c*c; so >= b; b++){
    for(a = c; a >= i; i++){
        for(d = c; a >= k; k++){
            for(e = c; a >= j; j++){
                result = result + koyakusu(koyakusu(a,d),e);
                
                
            }
        }
        
    }
    }
    printf("%d",result);
    return result;
}