#include <bits/stdc++.h>
using namespace std;
struct data {
  long long x, y, z;
  data(long long _x, long long _y, long long _z) : x(_x), y(_y), z(_z){};
};
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long n;
vector<long long> allVal;
vector<data> inp;
vector<vector<pair<long long, long long> > > a(200005);
void purify(pair<long long, long long> &c) {
  long long xgcd = gcd(c.first, c.second);
  c.first /= xgcd;
  c.second /= xgcd;
}
long long fact(long long x) {
  long long ret = 1;
  for (long long i = 2; i <= sqrt(x); i++) {
    long long buff = 0;
    while (x % i == 0) {
      buff++;
      x /= i;
    }
    ret *= (buff + 1);
  }
  if (x > 1) ret *= 2;
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    allVal.push_back(x);
    inp.push_back(data(x, y, z));
  }
  sort(allVal.begin(), allVal.end());
  allVal.resize(distance(allVal.begin(), unique(allVal.begin(), allVal.end())));
  for (auto &it : inp) {
    it.x = lower_bound(allVal.begin(), allVal.end(), it.x) - allVal.begin();
    a[it.x].push_back(make_pair(it.y, it.z));
  }
  sort(a[0].begin(), a[0].end());
  long long allLcm = 1;
  for (long long i = 1; i < allVal.size(); i++) {
    sort(a[i].begin(), a[i].end());
    if (a[0].size() != a[i].size()) {
      cout << 0 << '\n';
      return 0;
    }
    for (long long j = 0; j < a[i].size(); j++) {
      if (a[0][j].first != a[i][j].first) {
        cout << 0 << '\n';
        return 0;
      }
    }
    pair<long long, long long> pre = make_pair(a[0][0].second, a[i][0].second);
    purify(pre);
    for (long long j = 1; j < a[i].size(); j++) {
      pair<long long, long long> cur =
          make_pair(a[0][j].second, a[i][j].second);
      purify(cur);
      if (cur != pre) {
        cout << 0 << '\n';
        return 0;
      }
    }
    allLcm = lcm(allLcm, pre.first);
    if (allLcm > 1e12) {
      cout << 0 << '\n';
      return 0;
    }
  }
  long long allGcd = a[0][0].second;
  for (auto it : a[0]) allGcd = gcd(allGcd, it.second);
  if (allGcd % allLcm != 0) {
    cout << 0 << '\n';
    return 0;
  }
  cout << fact(allGcd / allLcm) << '\n';
}
