#include <iostream>
#include <string>
using namespace std;

int yakusuu(int a, int b){
    int r, tmp;
    if(a < b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}
int main(){

    int n, i, j, k;
    long int sum=0;
    cin >> n;

    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                sum += yakusuu(yakusuu(i,j),k);
            }
        }
    }

    cout << sum << endl;
    return 0;

}