#include <bits/stdc++.h>
using namespace std;
const int N = 202020;
int n, cntw;
long long w[N], h[N], c[N], d[N];
map<long long, int> W;
vector<pair<long long, long long> > a[N];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  scanf("%d", &n);
  long long D = 0;
  for (int i = (1); i < (n + 1); i++)
    scanf("%lld%lld%lld", w + i, h + i, c + i), D = gcd(D, c[i]);
  for (int i = (1); i < (n + 1); i++) c[i] /= D;
  for (int i = (1); i < (n + 1); i++) {
    if (!W.count(w[i])) W[w[i]] = ++cntw;
    a[W[w[i]]].push_back(make_pair(h[i], c[i]));
  }
  for (int i = (1); i < (cntw + 1); i++) {
    sort(a[i].begin(), a[i].end());
    for (int j = (0); j < ((int)a[i].size()); j++) {
      d[i] = gcd(d[i], a[i][j].second);
    }
    for (int j = (0); j < ((int)a[i].size()); j++) {
      a[i][j].second /= d[i];
    }
    if (i > 1) {
      for (int j = (0); j < ((int)a[i].size()); j++) {
        if (a[i][j].first != a[1][j].first ||
            a[i][j].second != a[1][j].second) {
          puts("0");
          return 0;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 1; 1ll * i * i <= D; ++i)
    if (D % i == 0) {
      ++ans;
      if (i != D / i) ++ans;
    }
  printf("%d\n", ans);
  return 0;
}
