//ABC 162 C
#include <iostream>
using namespace std;

int gcd(int a,int b){
    if(a % b == 0){
        return(b);
    }else{
        return gcd(b , a % b)
    }

}
int main(){
    long long int a,b,c,d;
    b = c = d = 0;
    cin >> a;
    for(int i = 1;i <= a;i++){
        for(int ii = 1;ii <= a;ii++){
            for(int iii = 1;iii <= a;iii++){
                b = gcd(i,ii);
                c = gcd(b,iii);
                d = d + c;
            }
        }
    }
    cout << d << endl;


}