#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const long long mo = (long long)1e9 + 7;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
map<long long, map<long long, long long> > mp;
map<long long, long long> cnt;
vector<pair<long long, long long> > v[210000];
void work() {
  int n;
  cin >> n;
  long long w, h, c;
  for (int i = 1; i <= n; i++) {
    cin >> w >> h >> c;
    mp[w].insert({h, c});
  }
  auto p = mp.begin();
  while (p != mp.end()) {
    cnt[p->second.size()]++;
    p++;
  }
  if (cnt.size() != 1) {
    cout << "0\n";
    return;
  }
  if (mp.size() == 1) {
    p = mp.begin();
    map<long long, long long> tmp = p->second;
    auto q = tmp.begin();
    long long g = q->second;
    q++;
    while (q != tmp.end()) {
      g = gcd(g, q->second);
      q++;
    }
    long long top = sqrt(g);
    long long ans = 0;
    for (int i = 1; i <= top; i++) {
      if (g % i == 0) {
        ans++;
        if (i != g / i) ans++;
      }
    }
    cout << ans << "\n";
  } else {
    p = mp.begin();
    map<long long, long long> tmp;
    int cur = 0;
    while (p != mp.end()) {
      ++cur;
      tmp = p->second;
      auto q = tmp.begin();
      while (q != tmp.end()) {
        v[cur].push_back({q->first, q->second});
        q++;
      }
      p++;
    }
    if (v[1].size() == 1) {
      for (int i = 2; i <= cur; i++) {
        if (v[i][0].first != v[i - 1][0].first) {
          cout << "0\n";
          exit(0);
        }
      }
    } else {
      for (int i = 2; i <= cur; i++) {
        for (int j = 0; j < v[i].size() - 1; j++) {
          if (v[i][j].first != v[i - 1][j].first ||
              v[i - 1][j].second * v[i][j + 1].second !=
                  v[i - 1][j + 1].second * v[i][j].second) {
            cout << "0\n";
            exit(0);
          }
        }
      }
    }
    long long g = 0;
    for (int i = 1; i <= cur; i++) {
      for (int j = 0; j < v[i].size(); j++) {
        g = gcd(v[i][j].second, g);
      }
    }
    long long top = sqrt(g);
    long long ans = 0;
    for (int i = 1; i <= top; i++) {
      if (g % i == 0) {
        ans++;
        if (i != g / i) ans++;
      }
    }
    cout << ans << "\n";
  }
}
int main() {
  work();
  return 0;
}
