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

long long int gcd(long long int num1,long long int num2){
    if(num1 < num2){
        int tmp = num1;
        num1 = num2;
        num2 = tmp;
    }

    int r = num1 % num2;
    while(r != 0){
        num1 = num2;
        num2 = r;
        r = num1 % num2;
    }

    return num2;
}

int main(){
    int k;
    long long int sum = 0;
    scanf("%d",&k);
    for(int i = 1;i <= k;i++){
        for(int j = 1;j <= k;j++){
            int r1 = gcd(i,j);
            for(int l = 1;l <= k;l++){
                sum += gcd(r1,l);
            }
        }
    }
    printf("%lld",sum);
    return 0;
}
