#include<stdio.h>

int Euclid(int a,int b){
    int r;
    while(1){
        r = a % b;
        if(r == 0){
            break;
        }
        a  = b;
        b = r;
        
    }
    return b;
}
int main(){
    int n;
    scanf("%d",&n);
    int sum = 0;
    int d;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            for(int k = 1;k <= n;k++){
                d = Euclid(i,j);
                if(j == k || i == k){
                    sum += d;
                    
                    continue;
                }
                d = Euclid(d,k);
                sum += d;
               
            }
        }
    }
    printf("%d\n",sum);
}