#include <bits/stdc++.h>
using namespace std;
int n;
long long seq[400000];
int r, c;
map<long long, int> row;
map<long long, int> col;
long long w[300000], h[300000], num[300000];
long long rgcd[300000], cgcd[300000];
long long ans, temp, a;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  r = 0;
  c = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d %I64d %I64d", &w[i], &h[i], &num[i]);
    if (row.count(w[i]) == 0) row[w[i]] = r++;
    if (col.count(h[i]) == 0) col[h[i]] = c++;
  }
  if (r * c != n) {
    printf("0\n");
    return 0;
  }
  int x, y;
  for (int i = 0; i < n; ++i) {
    x = row[w[i]];
    y = col[h[i]];
    seq[x * c + y] = num[i];
  }
  for (int i = 0; i < r; ++i) {
    rgcd[i] = seq[i * c];
    for (int j = 1; j < c; ++j) {
      rgcd[i] = gcd(rgcd[i], seq[i * c + j]);
    }
    if (i > 0) {
      for (int j = 0; j < c; ++j)
        if (seq[i * c + j] / rgcd[i] != seq[j] / rgcd[0]) {
          printf("0\n");
          return 0;
        }
    }
  }
  for (int j = 0; j < c; ++j) {
    cgcd[j] = seq[j];
    for (int i = 1; i < r; ++i) {
      cgcd[j] = gcd(cgcd[j], seq[i * c + j]);
    }
    if (j > 0) {
      for (int i = 0; i < r; ++i)
        if (seq[i * c + j] / cgcd[j] != seq[i * c] / cgcd[0]) {
          printf("0\n");
          return 0;
        }
    }
  }
  ans = 0;
  a = seq[0];
  long long u, v;
  for (long long i = 1; i * i <= a; ++i) {
    u = i;
    if (a % u != 0) continue;
    v = a / u;
    if (rgcd[0] % u == 0 && cgcd[0] % v == 0) ++ans;
    u = a / i;
    if (u == i) continue;
    v = a / u;
    if (rgcd[0] % u == 0 && cgcd[0] % v == 0) ++ans;
  }
  printf("%I64d\n", ans);
  return 0;
}
