#include <bits/stdc++.h>
using namespace std;
const int maxn = int(2e5) + 100;
int n;
long long w[maxn], h[maxn], cnt[maxn];
void read() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%lld%lld%lld", &w[i], &h[i], &cnt[i]);
}
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
void solve() {
  sort(w + 1, w + 1 + n);
  sort(h + 1, h + 1 + n);
  int s1 = 0, s2 = 0;
  for (int i = 1; i <= n; ++i)
    if (w[i] != w[i - 1]) s1++;
  for (int i = 1; i <= n;) {
    ++s2;
    int j = i;
    while (j <= n && h[j] == h[i]) ++j;
    if (j - i != s1) {
      puts("0");
      return;
    }
    i = j;
  }
  long long d = 0;
  for (int i = 1; i <= n; ++i) d = gcd(d, cnt[i]);
  if (d == 1 && (s1 != 1 && s2 != 1)) {
    puts("0");
    return;
  }
  long long ans = 0;
  long long fin = sqrt(d);
  while (fin * fin <= d) ++fin;
  for (long long i = 1; i < fin; ++i)
    if (d % i == 0) ans += 2 - (i == d / i);
  printf("%lld\n", ans);
}
int main() {
  read();
  solve();
  return 0;
}
