#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
map<pair<pair<int, int>, int>, int> vis;
struct point {
  double x, y;
};
struct line {
  point v, u;
} mapp[1010];
int gcd(int x, int y) {
  int t;
  while (y) {
    t = y;
    y = x % y;
    x = t;
  }
  return x;
}
double cal(point a, point b, point c) {
  return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
}
double getk(point x, point y) {
  return (double)(y.y - x.y) / (double)(y.x - x.x);
}
bool judge(point a, point b, point c, point d) {
  if (cal(a, b, c) * cal(a, b, d) < eps && cal(c, d, a) * cal(c, d, b) < eps &&
      getk(a, b) != getk(c, d))
    return true;
  else
    return false;
}
point getpoint(point a, point b, point c, point d) {
  point res;
  double a1, b1, c1, a2, b2, c2;
  a1 = a.y - b.y, b1 = b.x - a.x, c1 = a.x * b.y - b.x * a.y;
  a2 = c.y - d.y, b2 = d.x - c.x, c2 = c.x * d.y - d.x * c.y;
  res.x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
  res.y = -(a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
  return res;
}
bool isint(double x) {
  double t1;
  int t2;
  t2 = x;
  t1 = t2;
  if (fabs(x - t1) < eps)
    return true;
  else
    return false;
}
int main() {
  int n, x1, y1, x2, y2;
  long long ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    mapp[i].v.x = x1;
    mapp[i].v.y = y1;
    mapp[i].u.x = x2;
    mapp[i].u.y = y2;
    ans += gcd(abs(x1 - x2), abs(y1 - y2)) + 1;
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      if (judge(mapp[i].v, mapp[i].u, mapp[j].v, mapp[j].u)) {
        point s = getpoint(mapp[i].v, mapp[i].u, mapp[j].v, mapp[j].u);
        if (isint(s.x) && isint(s.y)) {
          x1 = s.x;
          y1 = s.y;
          if (vis[make_pair(make_pair(x1, y1), i)] == 0 ||
              vis[make_pair(make_pair(x1, y1), j)] == 0) {
            ans--;
            vis[make_pair(make_pair(x1, y1), i)] = 1;
            vis[make_pair(make_pair(x1, y1), j)] = 1;
          }
        }
      }
    }
  printf("%I64d\n", ans);
  return 0;
}
