#include <stdio.h>
typedef long long ll;

ll calc_gcd(ll a, ll b){
    ll  r, tmp;

    //大小入れ替え
    if( a < b ){
        tmp = a;
        a = b;
        b = tmp;
    }

    //ユークリッドの互除法
    r = a % b;
    while( r ){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main(){
    int k,sum=0;
    scanf("%d",&k);

    for(int a=1; a<=k; a++){
        for(int b=1; b<=k; b++){
            for(int c=1; c<=k; c++){
                sum += calc_gcd( a, calc_gcd(b,c) );
            }
        }
    }
    printf("%d\n",sum);
    return 0;
}