#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
map<long long, int> fi;
map<long long, int> se;
map<pair<long long, long long>, long long> all;
int n;
long long mult(long long a, long long b) {
  if (a > INF / b) {
    cout << 0;
    exit(0);
  }
  return a * b;
}
long long gcd(long long a, long long b) {
  while (a > 0 && b > 0) {
    if (a < b) swap(a, b);
    a %= b;
  }
  return a + b;
}
long long lcm(long long a, long long b) {
  long long aa = a / gcd(a, b);
  return mult(aa, b);
}
long long divisors(long long A) {
  assert(A <= (1e13));
  long long ans = 0;
  for (int i = 1; 1LL * i * i <= A; i++) {
    if ((A % i) == 0) {
      if (i != (A / i))
        ans += 2;
      else
        ans += 1;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  srand(time(0));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long w, h, c;
    cin >> w >> h >> c;
    all[make_pair(w, h)] = c;
    fi[w]++;
    se[h]++;
  }
  vector<long long> fic, sec;
  for (auto it = fi.begin(); it != fi.end(); it++) {
    fic.push_back((*it).first);
  }
  for (auto it = se.begin(); it != se.end(); it++) {
    sec.push_back((*it).first);
  }
  int fiz = fic.size();
  int sez = sec.size();
  if (1LL * fiz * sez != n) {
    cout << 0;
    return 0;
  }
  vector<vector<long long> > matrix;
  matrix.resize(fiz, vector<long long>(sez, 0));
  for (int i = 0; i < fic.size(); i++) {
    for (int j = 0; j < sec.size(); j++) {
      long long val = all[make_pair(fic[i], sec[j])];
      if (val == 0) {
        cout << 0;
        return 0;
      }
      matrix[i][j] = val;
    }
  }
  long long curA = matrix[0][0];
  for (int i = 0; i < sez; i++) {
    curA = gcd(curA, matrix[0][i]);
  }
  long long curB = 1;
  for (int i = 0; i < fiz; i++) {
    curB = lcm(curB, matrix[0][0] / gcd(matrix[i][0], matrix[0][0]));
  }
  if (curA % curB != 0) {
    cout << 0;
    return 0;
  }
  vector<long long> sampF(fiz);
  vector<long long> sampS(sez);
  long long x = curB;
  for (int i = 0; i < fiz; i++) {
    long long d = gcd(matrix[i][0], matrix[0][0]);
    sampF[i] = mult((x / (matrix[0][0] / d)), matrix[i][0] / d);
  }
  for (int i = 0; i < sez; i++) {
    sampS[i] = (matrix[0][i] / x);
  }
  for (int i = 0; i < fiz; i++) {
    for (int j = 0; j < sez; j++) {
      if (mult(sampF[i], sampS[j]) != matrix[i][j]) {
        cout << 0;
        return 0;
      }
    }
  }
  cout << divisors(curA / curB);
  return 0;
}
