#include <bits/stdc++.h>
std::map<long long int, int> mw, mh;
std::map<std::pair<int, int>, long long int> map;
int nw, nh;
long long int sw[262144], sh[262144];
long long int gw, gh, gc;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
int count(long long int k) {
  int ans = 1, s;
  for (int i = 2; i * i <= k; ++i) {
    if (k % i) continue;
    s = ans;
    do k /= i, ans += s;
    while (!(k % i));
  }
  if (k != 1) ans <<= 1;
  return ans;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    long long int w, h, c;
    scanf("%lld%lld%lld", &w, &h, &c);
    int &rw = mw[w], &rh = mh[h];
    if (!rw) rw = ++nw;
    if (!rh) rh = ++nh;
    sw[rw] += c;
    sh[rh] += c;
    gc = gcd(gc, c);
    map[std::pair<int, int>(rw, rh)] = c;
  }
  for (int i = 1; i <= nw; ++i) gw = gcd(gw, sw[i]);
  for (int i = 1; i <= nw; ++i) sw[i] /= gw;
  for (int i = 1; i <= nh; ++i) gh = gcd(gh, sh[i]);
  for (int i = 1; i <= nh; ++i) sh[i] /= gh;
  for (int i = 1; i <= nw; ++i)
    for (int j = 1; j <= nh; ++j)
      if (sw[i] * sh[j] * gc != map[std::pair<int, int>(i, j)]) goto tag_false;
  printf("%d\n", count(gc));
  return 0;
tag_false:
  return puts("0"), 0;
}
