#include <bits/stdc++.h>
using namespace std;
long long w[200009], h[200009], c[200009];
long long mulw[200009], mulh[200009], divw[200009], divh[200009];
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int cntdiv(long long N) {
  int cnt = 0;
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      cnt++;
      if (i * i != N) cnt++;
    }
  }
  return cnt;
}
int main() {
  int N;
  scanf("%d", &N);
  map<long long, int> idw, idh;
  int cntw = 0, cnth = 0;
  for (int i = 0; i < N; i++) {
    scanf("%I64d %I64d %I64d", &w[i], &h[i], &c[i]);
    if (!idw.count(w[i])) {
      mulw[cntw] = 1;
      divw[cntw] = 0;
      idw[w[i]] = cntw++;
    }
    if (!idh.count(h[i])) {
      mulh[cnth] = 1;
      divh[cnth] = 0;
      idh[h[i]] = cnth++;
    }
  }
  bool ok = true;
  if (cntw * cnth != N) ok = false;
  if (ok) {
    vector<vector<bool> > app;
    app.resize(cntw);
    for (int i = 0; i < cntw; i++) app[i].assign(cnth, false);
    for (int i = 0; i < N; i++) {
      w[i] = idw[w[i]];
      h[i] = idh[h[i]];
      app[w[i]][h[i]] = true;
    }
    for (int i = 0; i < cntw; i++)
      for (int j = 0; j < cnth; j++) {
        if (!app[i][j]) ok = false;
      }
  }
  while (ok) {
    bool changed = false;
    for (int i = 0; i < N; i++) {
      long long cur;
      cur = gcd(divw[w[i]], c[i] / (mulh[h[i]] == 0 ? 1 : mulh[h[i]]));
      if (divw[w[i]] != cur) {
        divw[w[i]] = cur;
        changed = true;
      }
      cur = gcd(divh[h[i]], c[i] / (mulw[w[i]] == 0 ? 1 : mulw[w[i]]));
      if (divh[h[i]] != cur) {
        divh[h[i]] = cur;
        changed = true;
      }
      cur = lcm(mulw[w[i]], c[i] / (divh[h[i]] == 0 ? 1 : divh[h[i]]));
      if (mulw[w[i]] != cur) {
        mulw[w[i]] = cur;
        changed = true;
      }
      cur = lcm(mulh[h[i]], c[i] / (divw[w[i]] == 0 ? 1 : divw[w[i]]));
      if (mulh[h[i]] != cur) {
        mulh[h[i]] = cur;
        changed = true;
      }
      if (divh[h[i]] < mulh[h[i]] || divh[h[i]] % mulh[h[i]] != 0) {
        ok = false;
        break;
      }
      if (divw[w[i]] < mulw[w[i]] || divw[w[i]] % mulw[w[i]] != 0) {
        ok = false;
        break;
      }
    }
    if (!changed) break;
  }
  int ans = ok ? cntdiv(divw[w[0]] / mulw[w[0]]) : 0;
  printf("%d\n", ans);
  return 0;
}
