#include <bits/stdc++.h>
using namespace std;
const long long linf = 1LL << 62;
const int iinf = 1 << 30;
const double dinf = 1e17;
const int Mod = 1e9 + 9;
const int maxn = 1000005;
int n;
struct Point {
  long long x, y;
  int id;
  Point(long long x = 0, long long y = 0) : x(x), y(y) {}
  Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); }
  bool operator==(const Point &a) const { return x == a.x && y == a.y; }
};
long long gcd(long long a, long long b) {
  long long t;
  while (b > 0) {
    t = b;
    b = a % b;
    a = t;
  }
  return a;
}
long long Cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
long long Dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
bool onsg(Point p, Point a1, Point a2) {
  return Cross(a1 - p, a2 - p) == 0 && Dot(a1 - p, a2 - p) < 0;
}
void ck(long long &c) {
  if (c > 0)
    c = 1;
  else if (c < 0)
    c = -1;
}
int Ins(Point a1, Point a2, Point b1, Point b2) {
  if (a1 == b1 || a1 == b2 || a2 == b1 || a2 == b2) return 1;
  if (onsg(a1, b1, b2) || onsg(a2, b1, b2) || onsg(b1, a1, a2) ||
      onsg(b2, a1, a2))
    return 1;
  long long c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1);
  long long c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);
  ck(c1);
  ck(c2);
  ck(c3);
  ck(c4);
  return c1 * c2 < 0 && c3 * c4 < 0;
}
set<pair<long long, long long> > c;
void chk(Point p, Point v, Point q, Point w) {
  Point u = p - q;
  long long v1 = Cross(w, u), v2 = Cross(v, w);
  if (abs(v1 * v.x) % v2 != 0 || abs(v1 * v.y) % v2 != 0) return;
  long long xx, yy;
  xx = p.x + v.x * v1 / v2;
  yy = p.y + v.y * v1 / v2;
  c.insert(make_pair(xx, yy));
}
struct segm {
  Point p1, p2;
};
segm ss[maxn];
Point p1, p2;
void solve() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> p1.x >> p1.y >> p2.x >> p2.y;
    ss[i].p1 = p1;
    ss[i].p2 = p2;
    ans += gcd(abs(ss[i].p2.x - ss[i].p1.x), abs(ss[i].p2.y - ss[i].p1.y)) + 1;
  }
  for (int i = 1; i <= n; i++) {
    c.clear();
    for (int j = i + 1; j <= n; j++) {
      int ct = Ins(ss[i].p1, ss[i].p2, ss[j].p1, ss[j].p2);
      if (ct) chk(ss[i].p1, ss[i].p2 - ss[i].p1, ss[j].p1, ss[j].p2 - ss[j].p1);
    }
    ans -= c.size();
  }
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
