#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 50;
int n;
long long w[MAXN], h[MAXN], c[MAXN];
map<long long, int> wMap, hMap;
int wNume = 0, hNume = 0;
set<long long> wSet[MAXN], hSet[MAXN];
map<long long, long long> matrix[MAXN];
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  scanf("%d", &n);
  long long g = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &w[i], &h[i], &c[i]);
    if (wMap[w[i]] == 0) wMap[w[i]] = ++wNume;
    if (hMap[h[i]] == 0) hMap[h[i]] = ++hNume;
    wSet[wMap[w[i]]].insert(h[i]);
    hSet[hMap[h[i]]].insert(w[i]);
    matrix[wMap[w[i]]][hMap[h[i]]] = c[i];
    g = gcd(g, c[i]);
  }
  for (int i = 1; i <= wNume; i++) {
    if (wSet[i].size() != hNume) {
      puts("0");
      return 0;
    }
  }
  for (int i = 1; i <= hNume; i++) {
    if (hSet[i].size() != wNume) {
      puts("0");
      return 0;
    }
  }
  for (int i = 2; i <= wNume; i++) {
    for (int j = 1; j <= hNume; j++) {
      long long m0 = matrix[1][1], m1 = matrix[1][j];
      long long p0 = matrix[i][1], p1 = matrix[i][j];
      long long mg = gcd(m0, m1), pg = gcd(p0, p1);
      m0 /= mg;
      m1 /= mg;
      p0 /= pg;
      p1 /= pg;
      if (!(m0 == p0 && m1 == p1)) {
        puts("0");
        return 0;
      }
    }
  }
  long long ans = 0;
  for (long long i = 1; i * i <= g; i++) {
    if (g % i != 0) continue;
    ans++;
    if (i * i != g) ans++;
  }
  printf("%lld\n", ans);
  return 0;
}
