#include <bits/stdc++.h>
using namespace std;
const int oo = 1e6 + 1;
const int maxn = 1e3 + 1;
int n, res;
struct T_p {
  int x, y;
};
T_p a[maxn], b[maxn];
vector<T_p> v;
void Enter() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].x >> a[i].y >> b[i].x >> b[i].y;
    if (a[i].x > b[i].x) swap(a[i], b[i]);
  }
}
void Init() {}
int GCD(int m, int n) {
  if (m < n) swap(m, n);
  while (n > 0) {
    int r = m % n;
    m = n;
    n = r;
  }
  return m;
}
T_p CutInter(int i, int j) {
  long long a1 = b[i].y - a[i].y;
  long long b1 = -(b[i].x - a[i].x);
  long long c1 = -(a1 * a[i].x + b1 * a[i].y);
  long long a2 = b[j].y - a[j].y;
  long long b2 = -(b[j].x - a[j].x);
  long long c2 = -(a2 * a[j].x + b2 * a[j].y);
  if (a1 * b2 == a2 * b1) return {-oo, -oo};
  if ((b1 * c2 - b2 * c1) % (a1 * b2 - a2 * b1) != 0)
    return {-oo, -oo};
  else {
    int x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
    if (b1 == 0) {
      swap(a1, a2);
      swap(b1, b2);
      swap(c1, c2);
    }
    if ((-c1 - a1 * x) % b1 == 0) {
      int y = (-c1 - a1 * x) / b1;
      if (min(a[i].x, b[i].x) <= x && x <= max(a[i].x, b[i].x) &&
          min(a[j].x, b[j].x) <= x && x <= max(a[j].x, b[j].x) &&
          min(a[i].y, b[i].y) <= y && y <= max(a[i].y, b[i].y) &&
          min(a[j].y, b[j].y) <= y && y <= max(a[j].y, b[j].y))
        return {x, y};
      else
        return {-oo, -oo};
    } else
      return {-oo, -oo};
  }
}
int Sqrt(int x) {
  int l = 0;
  int r = 1e3;
  while (l <= r) {
    int m = (l + r) / 2;
    if (m * m < x + m)
      l = m + 1;
    else
      r = m - 1;
  }
  return l;
}
void Solve() {
  for (int i = 1; i <= n; ++i) {
    res += GCD(abs(a[i].x - b[i].x), abs(a[i].y - b[i].y)) + 1;
    for (int j = 1; j <= n; ++j) v.push_back(CutInter(i, j));
  }
  sort(v.begin(), v.end(),
       [](T_p p, T_p q) { return p.x < q.x || (p.x == q.x && p.y < q.y); });
  v.push_back({+oo, +oo});
  T_p pre = {-oo, -oo};
  int cnt = 1;
  for (auto p : v) {
    if (p.x == pre.x && p.y == pre.y)
      ++cnt;
    else {
      if (pre.x != -oo && pre.y != -oo) res -= Sqrt(cnt) - 1;
      pre.x = p.x;
      pre.y = p.y;
      cnt = 1;
    }
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Enter();
  Init();
  Solve();
}
