#include <iostream>
using namespace std;

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

int gcdthree(int a, int b, int c){
  int t = gcdtwo(a,b);
  int tt = gcdtwo(t,c);
  return tt;
}

int main(int argc, const char * argv[]) {
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
    
    int k;
    cin >> k;
    int sumN = 0;
    for(int a=1; a<=k; a++){
      for(int b=1; b<=k; b++){
        for(int c=1; c<=k; c++){
          sumN += gcdthree(a,b,c);
        }
      }
    }
    cout << sumN << endl;
    return 0;
}