#include <bits/stdc++.h>
using namespace std;
struct Pr {
  long long W;
  long long H;
  long long C;
};
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  map<long long, long long> a, b;
  vector<Pr> p;
  for (long long i = 0; i < n; i++) {
    long long W, H, C;
    cin >> W >> H >> C;
    long long asz = a.size(), bsz = b.size();
    if (!a.count(W)) a[W] = asz;
    if (!b.count(H)) b[H] = bsz;
    p.push_back({W, H, C});
  }
  long long P = a.size() * b.size();
  if (P != n) {
    cout << 0 << endl;
    return 0;
  }
  vector<vector<long long> > matrix;
  for (long long i = 0; i < a.size(); i++) {
    vector<long long> help;
    for (long long j = 0; j < b.size(); j++) help.push_back(0);
    matrix.push_back(help);
  }
  for (long long i = 0; i < n; i++) {
    matrix[a[p[i].W]][b[p[i].H]] = p[i].C;
  }
  for (long long j = 1; j < b.size(); j++) {
    for (long long i = 1; i < a.size(); i++) {
      long long A = matrix[i - 1][j - 1], B = matrix[i - 1][j],
                C = matrix[i][j - 1], D = matrix[i][j];
      long long G1 = gcd(A, B), G2 = gcd(C, D);
      A /= G1, B /= G1, C /= G2, D /= G2;
      if (A != C || B != D) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  long long ff = matrix[0][0];
  for (long long i = 1; i < b.size(); i++) ff = gcd(ff, matrix[0][i]);
  long long th = 1, INF = 1e18;
  for (long long i = 0; i < b.size(); i++) {
    for (long long j = 1; j < a.size(); j++) {
      long long rzmw = gcd(matrix[0][i], matrix[j][i]);
      long long tt = matrix[0][i] / rzmw;
      long long gg = gcd(th, tt);
      tt /= gg;
      if (INF / tt < th) {
        cout << 0 << endl;
        return 0;
      }
      th *= tt;
    }
  }
  if (ff % th != 0) {
    cout << 0 << endl;
    return 0;
  }
  ff /= th;
  long long dl = 0;
  for (long long i = 1; i * i <= ff; i++) {
    if (ff % i) continue;
    dl++;
    if (i * i != ff) dl++;
  }
  cout << dl << endl;
}
