#include <bits/stdc++.h>
using namespace std;
void fin(int first) {
  cout << first << endl;
  exit(0);
}
int n;
long long w[200005];
long long h[200005];
long long c[200005];
set<long long> leftmrs;
set<long long> rightmrs;
int func(vector<vector<long long>> all) {
  vector<long long> divs;
  for (long long d = 1; d * d <= all[0][0]; ++d)
    if (all[0][0] % d == 0) {
      divs.push_back(d);
      if (d * d != all[0][0]) divs.push_back(all[0][0] / d);
    }
  int cnt = 0;
  for (auto d : divs) {
    bool check = true;
    vector<long long> lv(leftmrs.size()), rv(rightmrs.size());
    long long dd = all[0][0] / d;
    for (int i = (int)(0); i < (int)(leftmrs.size()); ++i)
      if (all[i][0] % dd == 0)
        lv[i] = all[i][0] / dd;
      else
        check = false;
    for (int i = (int)(0); i < (int)(rightmrs.size()); ++i)
      if (all[0][i] % d == 0)
        rv[i] = all[0][i] / d;
      else
        check = false;
    if (!check) continue;
    for (int i = (int)(0); i < (int)(leftmrs.size()); ++i)
      for (int j = (int)(0); j < (int)(rightmrs.size()); ++j)
        if (all[i][j] != lv[i] * rv[j]) {
          check = false;
          break;
        }
    if (check) ++cnt;
  }
  return cnt;
}
vector<vector<long long>> extract(vector<vector<long long>> &all, long long p) {
  auto output = all;
  for (int i = (int)(0); i < (int)(all.size()); ++i)
    for (int j = (int)(0); j < (int)(all[0].size()); ++j) {
      output[i][j] = 1;
      while (all[i][j] % p == 0) all[i][j] /= p, output[i][j] *= p;
    }
  return output;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = (int)(0); i < (int)(n); ++i) cin >> w[i] >> h[i] >> c[i];
  for (int i = (int)(0); i < (int)(n); ++i) leftmrs.insert(w[i]);
  for (int i = (int)(0); i < (int)(n); ++i) rightmrs.insert(h[i]);
  if ((long long)leftmrs.size() * (long long)rightmrs.size() > (long long)n)
    fin(0);
  map<long long, int> leftM;
  map<long long, int> rightM;
  int tmp = 0;
  for (auto t : leftmrs) leftM[t] = tmp++;
  tmp = 0;
  for (auto t : rightmrs) rightM[t] = tmp++;
  vector<long long> leftV(leftmrs.begin(), leftmrs.end());
  vector<long long> rightV(rightmrs.begin(), rightmrs.end());
  vector<vector<long long>> all(leftmrs.size(),
                                vector<long long>(rightmrs.size()));
  for (int i = (int)(0); i < (int)(n); ++i)
    all[leftM[w[i]]][rightM[h[i]]] = c[i];
  vector<long long> primes = {2, 3, 5, 7, 11};
  int cnt = 1;
  for (auto p : primes) cnt *= func(extract(all, p));
  cout << cnt * func(all) << endl;
  return 0;
}
