#include <bits/stdc++.h>
using namespace std;
long long getint() {
  char ch = getchar();
  long long f = 1, x = 0;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return f * x;
}
const int N = 200200;
int n;
struct dat {
  long long w, h, c;
} a[N];
int bg[N], ed[N];
int cnt;
int ans;
bool operator<(const dat &a, const dat &b) {
  return (a.w == b.w) ? a.h < b.h : a.w < b.w;
}
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
bool validate() {
  for (int i = 2; i <= cnt; i++) {
    if (ed[i] - bg[i] != ed[i - 1] - bg[i - 1]) return false;
    for (int j = bg[i], k = bg[i - 1]; j <= ed[i]; j++, k++) {
      if (a[j].h != a[k].h) return false;
    }
    long long g1, g2;
    for (int j = bg[i], k = bg[i - 1]; j < ed[i]; j++, k++) {
      g1 = gcd(a[j].c, a[j + 1].c);
      g2 = gcd(a[k].c, a[k + 1].c);
      if (a[j].c / g1 != a[k].c / g2 || a[j + 1].c / g1 != a[k + 1].c / g2)
        return false;
    }
  }
  return true;
}
void init() {
  n = getint();
  for (int i = 1; i <= n; i++) {
    a[i].w = getint();
    a[i].h = getint();
    a[i].c = getint();
  }
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) {
    ++cnt;
    bg[cnt] = i;
    while (a[i].w == a[i + 1].w) i++;
    ed[cnt] = i;
  }
}
int main() {
  init();
  if (!validate()) {
    puts("0");
    return 0;
  }
  long long g = a[1].c;
  for (int i = 2; i <= n; i++) {
    g = gcd(g, a[i].c);
  }
  for (long long i = 1; i * i <= g; i++) {
    if (g % i == 0) {
      ans += (i * i == g) ? 1 : 2;
    }
  }
  printf("%d\n", ans);
  return 0;
}
