#include <bits/stdc++.h>
using namespace std;
struct nade {
  long long w, h, c;
} a[2000005];
map<long long, vector<pair<long long, long long> > > mp;
vector<pair<long long, long long> > c;
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
bool pan() {
  for (auto &x : mp) {
    if (x.second.size() != c.size()) return 0;
    int n = c.size();
    long long d = 0;
    for (int i = 0; i < n; i++) d = gcd(d, x.second[i].second);
    for (int i = 0; i < n; i++) {
      x.second[i].second /= d;
      if (x.second[i] != c[i]) return 0;
    }
  }
  return 1;
}
int n;
int main() {
  scanf("%d", &n);
  long long K = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &a[i].w, &a[i].h, &a[i].c);
    K = gcd(K, a[i].c);
    mp[a[i].w].push_back(pair<long long, long long>{a[i].h, a[i].c});
  }
  for (auto &x : mp) {
    for (auto &y : x.second) y.second /= K;
    sort(x.second.begin(), x.second.end());
  }
  c = mp.begin()->second;
  long long d = 0;
  for (auto &x : c) d = gcd(d, x.second);
  for (auto &x : c) x.second /= d;
  if (!pan()) return printf("0"), 0;
  int ans = 0, t = sqrt(K);
  for (int i = 1; i <= t; i++)
    if (K % i == 0) {
      ans++;
      if (1ll * i * i != K) ans++;
    }
  printf("%d", ans);
}
