#include <bits/stdc++.h>
using namespace std;
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
long long nextLL() {
  long long x;
  scanf("%lld", &x);
  return x;
}
string nextString() {
  string s;
  cin >> s;
  return s;
}
const int INF = 1e9;
const int MAXN = 2e5;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
int n;
long long w[MAXN + 10];
long long h[MAXN + 10];
long long c[MAXN + 10];
map<long long, long long> cntw, cnth;
long long cntc;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  a %= b;
  return gcd(b, a);
}
int main() {
  int n = nextInt();
  for (int i = (0); i < (n); ++i) {
    w[i] = nextLL();
    h[i] = nextLL();
    c[i] = nextLL();
    cntw[w[i]] += c[i];
    cnth[h[i]] += c[i];
    cntc += c[i];
  }
  for (int i = (0); i < (n); ++i) {
    if (abs(1.0 * cntw[w[i]] / cntc - 1.0 * c[i] / cnth[h[i]]) > 1e-15) {
      printf("0");
      exit(0);
    }
  }
  long long g = c[0];
  long long res = 0;
  for (int i = (1); i < (n); ++i) g = gcd(g, c[i]);
  for (long long i = 1; i * i <= g; ++i) {
    if (g % i) continue;
    res++;
    if (i * i != g) res++;
  }
  printf("%lld", res);
}
