#include <bits/stdc++.h>

using namespace std;


int gcd(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 gcds(int a, int b, int c){
    int d = gcd(c,b);
    return gcd(a,d);
}

int main(){
    int K;
    cin >> K;

    long long res = 0;

    for(int i = 1;i<K+1;i++){
        for(int j = i;j<K+1;j++){
            for(int k=j;k<K+1;k++){
                int coef = 1;
                if(i == k || i == j || k == j){
                    if(i == k && i == j && k == j){
                        //全て同じ
                        coef = 1;
                    }
                    else{
                        //１組同じ
                        coef = 3;
                    }
                }
                else{
                    //全て違う
                    coef = 6;
                }
                res += gcds(i,j,k) * coef;
            }
        }
    }


    cout << res << endl;

}
