#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e5 + 10;
int64_t gcd(int64_t a, int64_t b) {
  while (b) {
    int64_t r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int N;
int64_t W[NMAX], H[NMAX], C[NMAX];
unordered_map<int64_t, int64_t> A, B;
int main() {
  scanf("%d", &N);
  int64_t cGcd = 0, cnt = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%I64d %I64d %I64d", &W[i], &H[i], &C[i]);
    A[W[i]] += C[i];
    B[H[i]] += C[i];
    cGcd = gcd(cGcd, C[i]);
    cnt += C[i];
  }
  int64_t aGcd = 0, sumB = 0;
  for (auto it : A) {
    aGcd = gcd(aGcd, it.second);
  }
  for (auto &it : A) {
    it.second /= aGcd;
    sumB += it.second;
  }
  int64_t bGcd = 0, sumA = 0;
  for (auto it : B) {
    bGcd = gcd(bGcd, it.second);
  }
  for (auto &it : B) {
    it.second /= bGcd;
    sumA += it.second;
  }
  if (sumA * sumB != cnt / cGcd) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < N; ++i) {
    if (A[W[i]] * B[H[i]] != C[i] / cGcd) {
      printf("0\n");
      return 0;
    }
  }
  int64_t answer = 1;
  for (int64_t i = 2; i * i <= cGcd; i += 2) {
    int cnt = 0;
    while (cGcd % i == 0) {
      ++cnt;
      cGcd /= i;
    }
    answer *= (cnt + 1);
    if (i == 2) --i;
  }
  if (cGcd > 1) answer *= 2;
  printf("%I64d\n", answer);
  return 0;
}
