#include <bits/stdc++.h>
using namespace std;
int n;
long long w[200005], h[200005], c[200005];
map<long long, long long> W, H;
vector<pair<long long, long long> > wv, hv;
map<pair<long long, long long>, long long> cnt;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  scanf("%d", &n);
  long long G = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld%lld%lld", &w[i], &h[i], &c[i]);
    W[w[i]] += c[i];
    H[h[i]] += c[i];
    cnt[make_pair(w[i], h[i])] = c[i];
    G = gcd(G, c[i]);
  }
  int ws = W.size();
  int wh = H.size();
  if (1LL * ws * wh != n) {
    puts("0");
    return 0;
  }
  for (map<long long, long long>::iterator it = W.begin(); it != W.end();
       ++it) {
    wv.push_back(make_pair(it->first, it->second));
  }
  for (map<long long, long long>::iterator it = H.begin(); it != H.end();
       ++it) {
    hv.push_back(make_pair(it->first, it->second));
  }
  vector<long long> V;
  for (int i = 0; i < wv.size(); i++) {
    for (int j = 0; j < hv.size(); j++) {
      long long a = cnt[make_pair(wv[i].first, hv[0].first)];
      long long b = hv[0].second;
      long long c = cnt[make_pair(wv[i].first, hv[j].first)];
      long long d = hv[j].second;
      long long A = a / gcd(a, b);
      long long B = b / gcd(a, b);
      long long C = c / gcd(c, d);
      long long D = d / gcd(c, d);
      if (A == C && B == D)
        ;
      else {
        puts("0");
        return 0;
      }
    }
  }
  for (int j = 0; j < hv.size(); j++) {
    for (int i = 0; i < wv.size(); i++) {
      long long a = cnt[make_pair(wv[0].first, hv[j].first)];
      long long b = wv[0].second;
      long long c = cnt[make_pair(wv[i].first, hv[j].first)];
      long long d = wv[i].second;
      long long A = a / gcd(a, b);
      long long B = b / gcd(a, b);
      long long C = c / gcd(c, d);
      long long D = d / gcd(c, d);
      if (A == C && B == D)
        ;
      else {
        puts("0");
        return 0;
      }
    }
  }
  int ans = 0;
  for (long long i = 1; i * i <= G; i++) {
    if (G % i == 0) ans++;
    if (G % i == 0 && i * i != G) ans++;
  }
  cout << ans << endl;
}
