#include <bits/stdc++.h>
using namespace std;
inline int gcd(int a, int b) {
  while (a && b)
    if (a > b)
      a %= b;
    else
      b %= a;
  return max(a, b);
}
int n;
int ax[1001], ay[1001], bx[1001], by[1001];
set<pair<int, int> > s[1001];
struct Point {
  int x, y;
};
struct Line {
  Point a, b;
};
inline Line makeline(int a, int b, int c, int d) {
  Line ans;
  ans.a.x = a;
  ans.a.y = b;
  ans.b.x = c;
  ans.b.y = d;
  return ans;
}
long long ans = 0;
inline int Abs(int x) { return x < 0 ? -x : x; }
inline int calc(int x) {
  int x1 = ax[x], y1 = ay[x], x2 = bx[x], y2 = by[x];
  if (x1 == x2) return Abs(y1 - y2) + 1;
  if (y1 == y2) return Abs(x1 - x2) + 1;
  int dx = x1 - x2, dy = y1 - y2;
  if (dx < 0) dx = -dx;
  if (dy < 0) dy = -dy;
  int kkk = gcd(dx, dy);
  return kkk + 1;
}
inline double dabs(double x) { return x < 0 ? -x : x; }
inline bool isint(double x) {
  double _lower = floor(x), _upper = ceil(x);
  return dabs(x - _lower) <= (1e-5) || dabs(x - _upper) <= (1e-5);
}
inline int getint(double x) {
  double _lower = floor(x), _upper = ceil(x);
  return dabs(x - _lower) <= (1e-5) ? _lower : _upper;
}
bool intersect(const Line& l1, const Line& l2, Point& inter) {
  int64_t a1 = l1.b.y - l1.a.y;
  int64_t a2 = l1.a.x - l1.b.x;
  int64_t a3 = a1 * l1.a.x + a2 * l1.a.y;
  int64_t b1 = l2.b.y - l2.a.y;
  int64_t b2 = l2.a.x - l2.b.x;
  int64_t b3 = b1 * l2.a.x + b2 * l2.a.y;
  int64_t det = b2 * a1 - b1 * a2;
  if (det == 0) {
    return false;
  }
  int64_t x = b2 * a3 - b3 * a2;
  int64_t y = b3 * a1 - b1 * a3;
  if (det < 0) {
    det = -det;
    x = -x;
    y = -y;
  }
  if (x % det != 0 || y % det != 0) {
    return false;
  }
  x /= det;
  y /= det;
  if (x < std::min(l1.a.x, l1.b.x) || x > std::max(l1.a.x, l1.b.x)) {
    return false;
  }
  if (x < std::min(l2.a.x, l2.b.x) || x > std::max(l2.a.x, l2.b.x)) {
    return false;
  }
  if (y < std::min(l1.a.y, l1.b.y) || y > std::max(l1.a.y, l1.b.y)) {
    return false;
  }
  if (y < std::min(l2.a.y, l2.b.y) || y > std::max(l2.a.y, l2.b.y)) {
    return false;
  }
  inter.x = x;
  inter.y = y;
  return true;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ax[i] >> ay[i] >> bx[i] >> by[i];
  for (int i = 1; i <= n; i++) {
    ans += 1ll * calc(i);
    for (int j = i + 1; j <= n; j++) {
      Point x;
      if (intersect(makeline(ax[i], ay[i], bx[i], by[i]),
                    makeline(ax[j], ay[j], bx[j], by[j]), x))
        s[i].insert(make_pair(x.x, x.y));
    }
    ans -= (int)s[i].size();
  }
  cout << ans;
}
