#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline long long read() {
  long long x = 0, f = 1;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch & 15);
    ch = getchar();
  }
  if (f)
    return x;
  else
    return -x;
}
const int N = 2e5 + 10;
int n, mw, mh;
long long w[N], h[N], c[N], w2[N], h2[N], g[N];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  n = (int)read();
  for (int i = 1; i <= n; i++)
    w2[i] = w[i] = read(), h2[i] = h[i] = read(), c[i] = read();
  sort(w2 + 1, w2 + 1 + n);
  sort(h2 + 1, h2 + 1 + n);
  mw = unique(w2 + 1, w2 + 1 + n) - w2 - 1;
  mh = unique(h2 + 1, h2 + 1 + n) - h2 - 1;
  if (mw * mh != n) {
    printf("0\n");
    return 0;
  }
  std::vector<long long> mp[mw + 1];
  for (int i = 1; i <= mw; i++) mp[i].resize(mh + 1);
  for (int i = 1; i <= n; i++)
    mp[lower_bound(w2 + 1, w2 + 1 + mw, w[i]) - w2]
      [lower_bound(h2 + 1, h2 + 1 + mh, h[i]) - h2] = c[i];
  for (int i = 1; i <= mw; i++)
    for (int j = 1; j <= mh; j++) g[i] = gcd(g[i], mp[i][j]), mp[i][j] /= g[i];
  for (int i = 2; i <= mw; i++)
    for (int j = 1; j <= mh; j++)
      if (mp[i][j] != mp[i - 1][j]) {
        printf("0\n");
        return 0;
      }
  long long G = 0ll;
  for (int i = 1; i <= mw; i++) G = gcd(G, g[i]);
  int ans = 0ll;
  for (long long i = 1ll; i * i < G; i++)
    if (G % i == 0) ans += 2;
  long long gg = sqrt(G);
  if (gg * gg == G) ans++;
  printf("%d\n", ans);
  return 0;
}
