#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 = 1;
    int b = 1;
    int d = 1;
    int i = 1;
    int k = 1;
    int j = 1;
    int x;
    int y;
    int so;
    so = c*c*c;
    
    for(a = 1; a >= i; i++){
        for(b = 1; b >= k; k++){
            for(d = 1; d >= j; j++){
                for(x = 1; so >= x; x++){
                    y = y + koyakusu(koyakusu(a,b),d);
                }
                
            }
        }
        
    }
    printf("%d",y);
    return y;
}
