#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
long long N, H[1 << 18], W[1 << 18], C[1 << 18], D[1 << 18], F[1 << 18];
vector<long long> X, Y;
map<pair<long long, long long>, long long> Map;
vector<long long> E[1 << 18];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  scanf("%lld", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%lld%lld%lld", &H[i], &W[i], &C[i]);
    Map[make_pair(H[i], W[i])] = C[i];
  }
  for (int i = 1; i <= N; i++) {
    X.push_back(H[i]);
    Y.push_back(W[i]);
  }
  sort(X.begin(), X.end());
  X.erase(unique(X.begin(), X.end()), X.end());
  sort(Y.begin(), Y.end());
  Y.erase(unique(Y.begin(), Y.end()), Y.end());
  for (int i = 0; i < X.size(); i++) {
    for (int j = 0; j < Y.size(); j++) {
      if (Map[make_pair(X[i], Y[j])] == 0) {
        cout << "0" << endl;
        return 0;
      }
      E[i].push_back(Map[make_pair(X[i], Y[j])]);
    }
  }
  long long Z = 0;
  for (int i = 0; i < E[0].size(); i++) Z = gcd(E[0][i], Z);
  for (int i = 0; i < E[0].size(); i++) D[i] = E[0][i] / Z;
  for (int i = 0; i < X.size(); i++) {
    for (int j = 0; j < Y.size(); j++) {
      if (E[i][j] % D[j] != 0) {
        cout << "0" << endl;
        return 0;
      }
      if (j == 0) F[i] = E[i][j] / D[j];
      if (F[i] != E[i][j] / D[j]) {
        cout << "0" << endl;
        return 0;
      }
    }
  }
  long long A = 0;
  for (int i = 0; i < X.size(); i++) A = gcd(F[i], A);
  int cnt = 0;
  for (long long i = 1; i * i <= A; i++) {
    if (A % i != 0) continue;
    cnt++;
    if (i != A / i) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
