#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int n;
long long a[200008], b[200008], c[200008];
bool check(vector<vector<pair<long long, long long>>>& v) {
  vector<long long> vc;
  for (int i = 0; i < v.size(); ++i) {
    long long g = 0;
    for (int j = 0; j < v[i].size(); ++j) g = gcd(g, v[i][j].second);
    vc.push_back(g);
  }
  for (int i = 1; i < v.size(); ++i) {
    if (v[i].size() != v[0].size()) return false;
    for (int j = 0; j < v[i].size(); ++j) {
      if (v[0][j].first != v[i][j].first) return false;
    }
  }
  for (int j = 0; j < v[0].size(); ++j) {
    for (int i = 0; i < v.size(); ++i) {
      if (v[i][j].second / vc[i] != v[0][j].second / vc[0]) return false;
    }
  }
  return true;
}
long long gao(unordered_map<long long, vector<pair<long long, long long>>>& mp,
              long long g) {
  vector<vector<pair<long long, long long>>> v;
  for (auto x : mp) {
    sort(mp[x.first].begin(), mp[x.first].end());
    v.push_back(mp[x.first]);
  }
  if (!check(v))
    return 0;
  else {
    long long ans = 0;
    for (long long i = 1; i * i <= g; ++i) {
      if (g % i == 0) ans += 1 + (i * i < g);
    }
    return ans;
  }
}
int main() {
  scanf("%d", &n);
  long long g = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%I64d %I64d %I64d", &a[i], &b[i], &c[i]);
    g = gcd(g, c[i]);
  }
  unordered_map<long long, vector<pair<long long, long long>>> mp;
  for (int i = 1; i <= n; ++i)
    mp[a[i]].push_back(pair<long long, long long>(b[i], c[i]));
  long long ans = gao(mp, g);
  mp.clear();
  for (int i = 1; i <= n; ++i)
    mp[b[i]].push_back(pair<long long, long long>(a[i], c[i]));
  cout << max(ans, gao(mp, g)) << endl;
}
