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

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


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

  int a, b, c; cin >> a >> b >> c;

  int ab, abc;
  int sum = 0;
  
  for (int i=1;i<=K;i++){
    for (int j=1;j<=K;j++){
      for (int k=1;k<=K;k++){
  	  ab = gcd(i, j);
	  abc = gcd(ab, k);
      sum += abc; 
      }
    }
  }
  
  cout << sum << endl;
}
