#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const double eps = 1e-6;
long long n, l, r, c;
vector<pair<long long, long long> > V[maxn];
map<long long, int> H, H2;
int tot = 0, tot2;
long long gcd(long long x, long long y) {
  return x % y == 0 ? y : gcd(y, x % y);
}
int main() {
  scanf("%I64d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d %I64d %I64d", &l, &r, &c);
    H[l] = H[l] ? H[l] : ++tot;
    V[H[l]].push_back(make_pair(r, c));
  }
  for (int i = 2; i <= tot; i++)
    if (V[i].size() != V[i - 1].size()) return 0 * printf("0\n");
  for (int i = 1; i <= tot; i++) sort(V[i].begin(), V[i].end());
  for (int i = 2; i <= tot; i++) {
    for (int j = 0; j < V[i].size(); j++)
      if (V[i][j].first != V[1][j].first) return 0 * printf("0\n");
    for (int j = 1; j < V[i].size(); j++) {
      if ((double)V[i][j].second * V[1][j - 1].second -
              (double)V[i][j - 1].second * V[1][j].second >
          eps)
        return 0 * printf("0\n");
    }
  }
  long long ans = V[1][0].second;
  for (int i = 1; i <= tot; i++)
    for (int j = 0; j < V[i].size(); j++) ans = gcd(ans, V[i][j].second);
  int cnt = 0;
  for (long long i = 1; i <= ans / i; i++) {
    if (ans % i == 0) {
      cnt++;
      if (ans / i != i) cnt++;
    }
  }
  printf("%d\n", cnt);
}
