#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long inf = numeric_limits<long long>::max() / 2;
const long double eps = 1e-9;
const long double pi = acos(-1);
template <typename T>
inline bool mineq(T& a, T b) {
  return (a > b) ? (a = b, 1) : 0;
}
template <typename T>
inline bool maxeq(T& a, T b) {
  return (a < b) ? (a = b, 1) : 0;
}
inline void solve(), read();
const string file = "";
signed main() {
  if (file != "") {
    freopen((file + ".in").c_str(), "r", stdin);
    freopen((file + ".out").c_str(), "w", stdout);
  }
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  read();
  solve();
  return 0;
}
long long gcd(long long a, long long b) {
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long n;
vector<long long> c;
map<long long, map<long long, long long> > ms;
inline void solve() {
  map<long long, long long> m1 = ms.begin()->second;
  for (auto it = next(ms.begin()); it != ms.end(); it++) {
    if (it->second != m1) {
      cout << 0 << "\n";
      return;
    }
  }
  long long g = 0;
  for (long long i = 0; i < n; i++) {
    g = gcd(g, c[i]);
  }
  for (long long i = 0; i < n; i++) {
    c[i] /= g;
  }
  long long ans = 2;
  for (long long i = 2; i * i <= g; i++) {
    if (g % i == 0) {
      ++ans;
      if (i * i != g) {
        ++ans;
      }
    }
  }
  if (g == 1) {
    ans = 1;
  }
  cout << ans << "\n";
}
inline void read() {
  cin >> n;
  c.resize(n);
  for (long long i = 0; i < n; i++) {
    long long w, h;
    cin >> w >> h >> c[i];
    ms[w][h] += c[i];
  }
  for (auto& p1 : ms) {
    long long minn = inf;
    for (auto& p2 : p1.second) {
      mineq(minn, p2.second);
    }
    for (auto& p2 : p1.second) {
      p2.second /= minn;
    }
  }
}
