#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
const double inf = 1e10, eps = 1e-8;
struct data {
  int lx, ly, rx, ry;
  double k() const {
    if (lx == rx) return inf;
    return double(ry - ly) / (rx - lx);
  }
  double b() const { return ly - lx * k(); }
  double f(int x) const { return k() * x + b(); }
} w[N];
map<pair<int, int>, int> S;
int tim;
int ans = 0;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
bool check(int x, int y) {
  if (S[make_pair(x, y)] == tim) return false;
  return S[make_pair(x, y)] = tim, true;
}
bool solve(const data &l, const data &r) {
  if (r.rx < l.lx || r.lx > l.lx) return false;
  double y = r.k() * l.lx + r.b();
  if (y < min(l.ly, l.ry) - eps || y > max(l.ly, l.ry) + eps) return false;
  if (fabs(ceil(y) - y) < eps) return check(l.lx, (int)ceil(y));
  if (fabs(floor(y) - y) < eps) return check(l.lx, (int)floor(y));
  return false;
}
bool calc(const data &l, const data &r) {
  if (fabs(l.k() - r.k()) < eps) return false;
  if (l.k() == inf && r.k() == inf)
    return false;
  else if (l.k() == inf)
    return solve(l, r);
  else if (r.k() == inf)
    return solve(r, l);
  double k1 = l.k(), b1 = l.b(), k2 = r.k(), b2 = r.b();
  double x = (b2 - b1) / (k1 - k2);
  int flag = 0;
  if (fabs(ceil(x) - x) < eps) x = ceil(x), flag = 1;
  if (fabs(floor(x) - x) < eps) x = floor(x), flag = 1;
  if (!flag || fabs(l.f(x) - r.f(x)) > eps) return false;
  if (x < l.lx - eps || x > l.rx + eps) return false;
  if (x < r.lx - eps || x > r.rx + eps) return false;
  double y = l.f(x);
  flag = 0;
  if (fabs(ceil(y) - y) < eps) y = ceil(y), flag = 1;
  if (fabs(floor(y) - y) < eps) y = floor(y), flag = 1;
  if (!flag) return false;
  return check((int)x, (int)y);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    ++tim;
    cin >> w[i].lx >> w[i].ly >> w[i].rx >> w[i].ry;
    if (w[i].lx > w[i].rx) swap(w[i].lx, w[i].rx), swap(w[i].ly, w[i].ry);
    ans += abs(gcd(w[i].rx - w[i].lx, w[i].ry - w[i].ly)) + 1;
    for (int j = 1; j < i; ++j)
      if (calc(w[j], w[i])) --ans;
  }
  cout << ans;
  return 0;
}
