#include <stdio.h>
int main(void){
    int K, a, x = 0;
    scanf("%d", &K);
    a = K / 2;
    int aa, bb, cc, mij = 0, z = 0, aaa, bbb, ccc, ma = 0, zz = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for(int k = 1; k <= K; k++){
                z = 0; zz = 0;
                aa = (i < j)? j : i;
                bb = (i < j)? i : j;
                while(z != 1){
                    cc = aa % bb;
                    if(cc == 0){
                        mij = bb;
                        z += 1;
                    }
                    else {
                        aa = bb;
                        bb = cc;
                    }
                }
                
                aaa = (mij < k)? k : mij;
                bbb = (mij < k)? mij : k;
                while(zz != 1){
                    ccc = aaa % bbb;
                    if(ccc == 0){
                        ma = bbb;
                        zz += 1;
                    }
                    else {
                        aaa = bbb;
                        bbb = ccc;
                    }
                }
                x += ma;
                
            }
        }
    }
    printf("%d\n", x);
  return 0;
}