#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int gcd3(int x, int y, int z) {

  for (int i = 1; i < z; i++) {
    x = gcd(x, y);
  }
  
  return x;
}

int main(){
    int N;
    long ans;

    ans = 0;

    cin >> N;

    for(int a=1; a<N+1;a++){
        for(int b=a; b<N+1;b++){
            for(int c=b; c<N+1;c++){
                if((a != b) && (b != c)){
                    ans += 6*gcd3(a,b,c);
                }
                else if((a == b) && (b != c)){
                    ans += 3*gcd3(a,b,c);
                }
                else if((a != b) && (b == c)){
                    ans += 3*gcd3(a,b,c);
                }
                else{
                    ans += gcd3(a,b,c);
                }
//                cout << a << b << c << gcd3(a,b,c) << ans << endl;
            }
        }
    }
    cout << ans << endl;

    return 0;
}