#include <bits/stdc++.h>
using namespace std;
int n, cur;
vector<pair<long long, long long> > v[200001];
unordered_map<long long, int> mm;
long long d[200001];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lowestterm(int u) {
  int sz = v[u].size();
  long long gc_div = v[u][0].second;
  for (int i = 1; i <= sz - 1; ++i) gc_div = gcd(gc_div, v[u][i].second);
  for (int i = 0; i <= sz - 1; ++i) v[u][i].second /= gc_div;
  return gc_div;
}
long long countDiv(long long x) {
  long long t = sqrt(x), res = 0;
  if (t * t == x)
    res = 1;
  else
    t++;
  while (--t)
    if (x % t == 0) res += 2;
  return res;
}
void setup() {
  cin >> n;
  long long w, h, c;
  for (int i = 1; i <= n; ++i) {
    cin >> w >> h >> c;
    if (mm.find(w) == mm.end()) mm[w] = ++cur;
    v[mm[w]].push_back({h, c});
  }
}
bool check(int i, int j) {
  if (v[i].size() != v[j].size()) return false;
  int l = v[i].size();
  for (int k = 0; k <= l - 1; ++k)
    if (v[i][k] != v[j][k]) return false;
  return true;
}
void process() {
  for (int i = 1; i <= cur; ++i) {
    sort(v[i].begin(), v[i].end());
    d[i] = lowestterm(i);
  }
  for (int i = 2; i <= cur; ++i)
    if (!check(i - 1, i)) {
      cout << 0;
      return;
    }
  long long gc_div = d[1];
  for (int i = 2; i <= cur; ++i) gc_div = gcd(gc_div, d[i]);
  cout << countDiv(gc_div);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  setup();
  process();
  return 0;
}
