#include <bits/stdc++.h>
using namespace std;

int main(void) {
  int K;
  cin >> K;
  int sum = 0;
  for(int i = 1; i <= K; i++) {
    for(int j = 1; j <= K; j++) {
      for(int k = 1; k <= K; k++) {
        int a = i,b = j;
	if(a > b) {
          int tmp = a;
          a = b;
          b = tmp;
        }
        int r = a % b;
        while(r != 0) {
          a = b;
          b = r;
          r = a % b;
        }
        a = k;
        if(a > b) {
          int tmp = a;
          a = b;
          b = tmp;
        }
        r = a % b;
        while(r != 0) {
          a = b;
          b = r;
          r = a % b;
        }
        sum += b;
      }
    }
  }
  cout << sum << endl;
  return 0;
}