#include <bits/stdc++.h>
using namespace std;
const int N = 234567;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
struct E {
  long long w, h, c;
  bool operator<(const E& rhs) const {
    if (h != rhs.h)
      return h < rhs.h;
    else if (w != rhs.w)
      return w < rhs.w;
    return c < rhs.c;
  }
} e[N];
int n;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> e[i].w >> e[i].h >> e[i].c;
  long long g = e[0].c;
  for (int i = 1; i < n; ++i) g = gcd(g, e[i].c);
  sort(e, e + n);
  vector<pair<long long, long long> > basic;
  for (int i = 0, j; i < n; i = j) {
    vector<pair<long long, long long> > par;
    for (j = i; j < n && e[j].h == e[i].h; ++j) {
      par.push_back(make_pair(e[j].w, e[j].c / g));
    }
    long long g0 = par[0].second;
    for (int k = 1; k < par.size(); ++k) g0 = gcd(g0, par[k].second);
    for (int k = 0; k < par.size(); ++k) par[k].second /= g0;
    if (basic.empty()) {
      for (int k = 0; k < par.size(); ++k) basic.push_back(par[k]);
    } else {
      if (par.size() != basic.size()) {
        cout << "0" << endl;
        return 0;
      }
      for (int k = 0; k < par.size(); ++k) {
        if (basic[k].first != par[k].first ||
            basic[k].second != par[k].second) {
          cout << "0" << endl;
          return 0;
        }
      }
    }
  }
  int res = 0;
  for (int i = 1; 1LL * i * i <= g; ++i) {
    if (g % i == 0) res += 1 + (g / i == i ? 0 : 1);
  }
  cout << res << endl;
  return 0;
}
