#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const long long P = 127;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  long long g = 0;
  map<long long, vector<pair<long long, long long> > > m;
  for (int i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    if (m.find(a) == m.end()) m[a] = vector<pair<long long, long long> >();
    m[a].emplace_back(b, c);
    g = gcd(g, c);
  }
  long long x = 0, y = 0;
  for (auto p : m) {
    long long tx = 0;
    long long ty = 0;
    sort(p.second.begin(), p.second.end());
    long long d = 0;
    for (int i = 0; i < p.second.size(); i++) d = gcd(d, p.second[i].second);
    for (int i = 0; i < p.second.size(); i++)
      tx = tx * P + p.second[i].first, ty = ty * P + p.second[i].second / d;
    if (x == 0) x = tx, y = ty;
    if (x != tx || y != ty) {
      cout << 0;
      return 0;
    }
  }
  long long res = 1;
  long long t = 2;
  while (t * t <= g) {
    if (g % t == 0) {
      int c = 0;
      while (g % t == 0) c++, g /= t;
      res *= c + 1;
    }
    t++;
  }
  if (g > 1) res *= 2;
  cout << res;
}
