#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
struct point {
  ll x, y;
};
struct segment {
  point p1, p2;
};
int sign(ll x) { return x < 0 ? -1 : 1; }
bool intersect(const segment& s1, const segment& s2, pair<ll, ll>* p) {
  ll x1 = s1.p1.x, x2 = s1.p2.x, x3 = s2.p1.x, x4 = s2.p2.x;
  ll y1 = s1.p1.y, y2 = s1.p2.y, y3 = s2.p1.y, y4 = s2.p2.y;
  ll den = (x4 - x3) * (y1 - y2) - (x1 - x2) * (y4 - y3);
  if (den == 0) return false;
  ll num1 = (y3 - y4) * (x1 - x3) + (x4 - x3) * (y1 - y3);
  if ((num1 > 0 && den < 0) || (num1 < 0 && den > 0) || abs(num1) > abs(den))
    return false;
  ll num2 = (y1 - y2) * (x1 - x3) + (x2 - x1) * (y1 - y3);
  if ((num2 > 0 && den < 0) || (num2 < 0 && den > 0) || abs(num2) > abs(den))
    return false;
  if ((x1 * den + num1 * (x2 - x1)) % den != 0) return false;
  if ((y1 * den + num1 * (y2 - y1)) % den != 0) return false;
  *p = {(x1 * den + num1 * (x2 - x1)) / den,
        (y1 * den + num1 * (y2 - y1)) / den};
  return true;
}
int main() {
  int n;
  cin >> n;
  vector<segment> v(n);
  for (auto& e : v) cin >> e.p1.x >> e.p1.y >> e.p2.x >> e.p2.y;
  ll ans = 0;
  set<pair<ll, ll>> intersections;
  for (int i = 0; i < n; ++i) {
    set<pair<ll, ll>> tmp_intersections;
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      pair<ll, ll> intersection;
      if (intersect(v[i], v[j], &intersection)) {
        intersections.insert(intersection);
        tmp_intersections.insert(intersection);
      }
    }
    ll xdiff = abs(v[i].p1.x - v[i].p2.x);
    ll ydiff = abs(v[i].p1.y - v[i].p2.y);
    ans += gcd(xdiff, ydiff) + 1 - tmp_intersections.size();
  }
  ans += intersections.size();
  cout << ans << endl;
  return 0;
}
