#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-15;
long long read() {
  char ch = getchar();
  long long x = 0;
  int op = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
  return x * op;
}
int n;
long long c[200005], w[200005], h[200005], sum, g, ans;
map<long long, long long> Mpw, Mph;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
int main() {
  n = read();
  g = 0;
  for (int i = (1); i <= (n); i++) {
    w[i] = read(), h[i] = read(), sum += (c[i] = read());
    Mpw[w[i]] += c[i];
    Mph[h[i]] += c[i];
    g = gcd(c[i], g);
  }
  for (int i = (1); i <= (n); i++)
    if (fabs((long double)1. * Mpw[w[i]] / sum -
             (long double)1. * c[i] / Mph[h[i]]) > eps) {
      puts("0");
      exit(0);
    }
  for (long long i = 1; i * i <= g; i++)
    if (g % i == 0) {
      ans++;
      if (i * i != g) ans++;
    }
  cout << ans << endl;
  return 0;
}
