#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
int n;
vector<pair<pair<long long, long long>, long long> > rect;
long long g;
map<long long, vector<pair<long long, long long> > > m;
map<long long, vector<pair<long long, long long> > >::iterator it;
set<vector<pair<long long, long long> > > st;
long long kilk(long long x) {
  long long res = 0;
  for (long long i = 1; i * i <= x; i++)
    if (x % i == 0) {
      res += 2;
      if (i * i == x) res--;
    }
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long h, w, c;
    cin >> w >> h >> c;
    if (!i)
      g = c;
    else
      g = gcd(g, c);
    rect.push_back(make_pair(make_pair(w, h), c));
  }
  for (int i = 0; i < n; i++) rect[i].second /= g;
  for (int i = 0; i < n; i++)
    m[rect[i].first.first].push_back(
        make_pair(rect[i].first.second, rect[i].second));
  for (it = m.begin(); it != m.end(); it++) {
    vector<pair<long long, long long> > cur = it->second;
    long long cur_g = cur[0].second;
    for (int i = 1; i < cur.size(); i++) cur_g = gcd(cur_g, cur[i].second);
    for (int i = 0; i < cur.size(); i++) cur[i].second /= cur_g;
    sort(cur.begin(), cur.end());
    st.insert(cur);
  }
  if (st.size() > 1)
    cout << 0;
  else
    cout << kilk(g);
}
