#include <bits/stdc++.h>
using namespace std;
const int SIZEN = 200010;
int N;
long long w[SIZEN], h[SIZEN], c[SIZEN];
map<long long, long long> wc, wh;
long long sum = 0;
long long g;
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    cin >> w[i] >> h[i] >> c[i];
    if (i == 1)
      g = c[i];
    else
      g = gcd(g, c[i]);
    wc[w[i]] += c[i];
    wh[h[i]] += c[i];
    sum += c[i];
  }
  bool flag = 0;
  for (int i = 1; i <= N; i++) {
    if (abs(1.0 * c[i] / wc[w[i]] - 1.0 * wh[h[i]] / sum) > 1e-15) {
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << 0 << endl;
  else {
    int ans = 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;
}
