#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-13;
const long double PI = acos(-1);
const int INF = (int)1e9;
const long long INFF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MXN = (int)2e5 + 7;
inline void bye() {
  puts("0");
  exit(0);
}
long long w[MXN], h[MXN], num[MXN];
int cnt[MXN];
map<long long, int> rr, cc;
vector<int> st[MXN];
long long gcdr[MXN], gcdc[MXN];
long long gcd(long long v1, long long v2) {
  while (v1) {
    long long tmp = v2 % v1;
    v2 = v1;
    v1 = tmp;
  }
  return v2;
}
int tmp[MXN];
int main() {
  int n;
  scanf("%d", &n);
  int r = 0, c = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld %lld %lld", w + i, h + i, num + i);
    if (w[i] == w[1]) {
      r++;
      rr[h[i]] = r;
    }
    if (h[i] == h[1]) {
      c++;
      cc[w[i]] = c;
    }
  }
  if (r * 1ll * c != n) bye();
  for (int i = 1; i <= r; i++) st[i].resize(c + 1);
  for (int i = 1; i <= n; i++) {
    int x = rr[h[i]], y = cc[w[i]];
    if (!x || !y) bye();
    st[x][y] = i;
  }
  for (int i = 1; i <= r; i++) {
    long long gd = num[st[i][1]];
    for (int j = 2; j <= c; j++) {
      gd = gcd(gd, num[st[i][j]]);
    }
    gcdr[i] = gd;
  }
  for (int j = 1; j <= c; j++) {
    long long gd = num[st[1][j]];
    for (int i = 2; i <= r; i++) {
      gd = gcd(gd, num[st[i][j]]);
    }
    gcdc[j] = gd;
  }
  long long v = num[1];
  if (v == 1) {
    for (int i = 1; i <= r; i++)
      for (int j = 1; j <= c; j++)
        if (st[i][j] != 1) bye();
  }
  long long h = max(2, (int)sqrt(v));
  long long ans = 1;
  for (int i = 2; i <= h; i++) {
    if (v % i == 0) {
      int sum = 0;
      while (v % i == 0) {
        v /= i;
        sum++;
      }
      int ll = 0, rr = sum;
      for (int j = 1; j <= n; j++) {
        cnt[j] = 0;
        while (num[j] % i == 0) {
          cnt[j]++;
          num[j] /= i;
        }
      }
      for (int k = 1; k <= c; k++) {
        tmp[k] = 0;
        while (gcdc[k] % i == 0) {
          tmp[k]++;
          gcdc[k] /= i;
        }
      }
      for (int j = 1; j <= r; j++) {
        for (int k = 1; k <= c; k++) {
          rr = min(rr, cnt[st[j][k]] + cnt[1] - cnt[st[j][1]]);
          ll = max(ll, cnt[st[j][k]] - tmp[k] + cnt[1] - cnt[st[j][1]]);
        }
      }
      if (ll <= rr) {
        ans *= (rr - ll + 1);
      } else {
        bye();
      }
    }
    if (i == h && v != 1) {
      h = v;
      i = h - 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
