#include <bits/stdc++.h>
using namespace std;
struct Segment {
  int x1, y1, x2, y2;
};
struct Line {
  long long a, b, c;
};
int n;
Segment seg[1005];
map<pair<int, int>, int> intersectCount;
unordered_map<int, int> toSubtract;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long det(long long a11, long long a12, long long a21, long long a22) {
  return a11 * a22 - a12 * a21;
}
pair<int, int> intersectLines(const Line &l1, const Line &l2) {
  long long detS = det(l1.a, l1.b, l2.a, l2.b);
  if (detS == 0) return make_pair(0x3f3f3f3f, 0x3f3f3f3f);
  long long detX = det(l1.c, l1.b, l2.c, l2.b);
  long long detY = det(l1.a, l1.c, l2.a, l2.c);
  if (detX % detS || detY % detS) return make_pair(0x3f3f3f3f, 0x3f3f3f3f);
  return make_pair(detX / detS, detY / detS);
}
Line segmentToLine(const Segment &s) {
  Line l;
  l.a = s.y1 - s.y2;
  l.b = s.x2 - s.x1;
  l.c = l.a * s.x1 + l.b * s.y1;
  return l;
}
pair<int, int> intersectSegments(const Segment &s1, const Segment &s2) {
  return intersectLines(segmentToLine(s1), segmentToLine(s2));
}
bool pointInSegment(const pair<int, int> &A, const Segment &s) {
  return min(s.x1, s.x2) <= A.first && A.first <= max(s.x1, s.x2) &&
         min(s.y1, s.y2) <= A.second && A.second <= max(s.y1, s.y2);
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> seg[i].x1 >> seg[i].y1 >> seg[i].x2 >> seg[i].y2;
  }
  long long sol = 0;
  for (int i = 1; i <= n; ++i) {
    sol += gcd(abs(seg[i].x1 - seg[i].x2), abs(seg[i].y1 - seg[i].y2)) + 1;
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      pair<int, int> A = intersectSegments(seg[i], seg[j]);
      if (A.first == 0x3f3f3f3f) continue;
      if (pointInSegment(A, seg[i]) && pointInSegment(A, seg[j])) {
        ++intersectCount[A];
      }
    }
  }
  int S = 0;
  for (int i = 1; i <= n; ++i) {
    S += i;
    toSubtract[S] = i;
  }
  for (auto first : intersectCount) {
    assert(toSubtract.count(first.second));
    sol -= toSubtract[first.second];
  }
  cout << sol << "\n";
  return 0;
}
