#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
  long long w, h, c;
} rect[200005];
bool cmp(const node& u, const node& v) {
  return u.w == v.w ? u.h < v.h : u.w < v.w;
}
long long gcd(long long u, long long v) {
  long long r = u % v;
  while (r) u = v, v = r, r = u % v;
  return v;
}
bool chk() {
  int cnt = 0;
  for (int i = 1; i <= n; i++) cnt += rect[i].w != rect[i - 1].w;
  if (n % cnt) return false;
  int m = n / cnt;
  for (int i = 1, ii = 0; i <= cnt; i++, ii += m)
    for (int j = 2; j <= m; j++)
      if (rect[ii + j].w != rect[ii + j - 1].w) return false;
  for (int i = 2, ii = m; i <= cnt; i++, ii += m)
    for (int j = 1; j <= m; j++)
      if (rect[ii + j].h != rect[ii + j - m].h) return false;
  long long aa, bb, cc, dd, gcdab, gcdcd;
  for (int i = 2; i <= cnt; i++) {
    aa = rect[1].c;
    bb = rect[(i - 1) * m + 1].c;
    gcdab = gcd(aa, bb);
    aa /= gcdab, bb /= gcdab;
    for (int j = 2; j <= m; j++) {
      cc = rect[j].c;
      dd = rect[(i - 1) * m + j].c;
      gcdcd = gcd(cc, dd);
      cc /= gcdcd, dd /= gcdcd;
      if (aa != cc || bb != dd) return false;
    }
  }
  return true;
}
int main() {
  scanf("%d", &n);
  rect[0].w = 0;
  for (int i = 1; i <= n; i++)
    scanf("%I64d%I64d%I64d", &rect[i].w, &rect[i].h, &rect[i].c);
  sort(rect + 1, rect + n + 1, cmp);
  if (!chk())
    puts("0");
  else {
    long long GCD = rect[1].c;
    for (int i = 2; i <= n; i++) GCD = gcd(GCD, rect[i].c);
    long long ans = 0;
    for (long long x = 1; x * x <= GCD; x++)
      if (!(GCD % x)) ans += (x == GCD / x ? 1 : 2);
    printf("%I64d\n", ans);
  }
  return 0;
}
