#include <bits/stdc++.h>
long long gcd(long long x, long long y) {
  if (x == 0 || y == 0) return x + y;
  return gcd(y, x % y);
}
int main() {
  std::map<long long, long long> cw, ch;
  std::vector<long long> wi, hi, ci;
  int n;
  scanf("%d", &n);
  wi.resize(n);
  hi.resize(n);
  ci.resize(n);
  long long g = 0, total = 0;
  for (int i = 0; i < n; ++i) {
    long long w, h, c;
    scanf("%lld %lld %lld", &w, &h, &c);
    cw[w] += c;
    ch[h] += c;
    wi[i] = w;
    hi[i] = h;
    ci[i] = c;
    g = gcd(g, c);
    total += c;
  }
  for (int i = 0; i < n; ++i) {
    double dw = 1.0 * cw[wi[i]] / total;
    double dh = 1.0 * ci[i] / ch[hi[i]];
    double dif = dw - dh;
    if (dif < 0) dif = -dif;
    if (dif > 1.0E-12) {
      printf("0\n");
      return 0;
    }
  }
  long long res = 0;
  for (long long i = 1; i * i <= g; ++i) {
    if (g % i == 0) {
      ++res;
      if (i * i != g) ++res;
    }
  }
  printf("%lld\n", res);
  return 0;
}
