#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
struct P {
  long long x, y;
};
long double ex(P s, P t, P r) {
  long double x1 = (long double)t.x - (long double)s.x;
  long double y1 = (long double)t.y - (long double)s.y;
  long double x2 = (long double)r.x - (long double)s.x;
  long double y2 = (long double)r.y - (long double)s.y;
  return x1 * y2 - x2 * y1;
}
bool cross(P a, P b, P s, P t) {
  if (ex(a, b, s) * ex(a, b, t) > 0) return false;
  if (ex(b, a, s) * ex(b, a, t) > 0) return false;
  if (ex(t, s, a) * ex(t, s, b) > 0) return false;
  return ex(s, t, a) * ex(s, t, b) < eps;
}
pair<bool, pair<long double, long double>> intersection_ls(P a1, P a2, P b1,
                                                           P b2) {
  long double d1 = abs(ex(b1, a1, b2));
  long double d2 = abs(ex(b1, a2, b2));
  if (!cross(a1, a2, b1, b2)) {
    return {false, {0.0, 0.0}};
  }
  return {true,
          {a1.x + (a2.x - a1.x) * d1 / (d1 + d2),
           a1.y + (a2.y - a1.y) * d1 / (d1 + d2)}};
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
void solve() {
  long long n;
  cin >> n;
  vector<pair<P, P>> vec;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;
    vec.push_back({P{ax, ay}, P{bx, by}});
    ans += gcd(abs(ax - bx), abs(ay - by)) + 1;
  }
  map<pair<long long, long long>, long long> mp;
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; ++j) {
      auto res = intersection_ls(vec[i].first, vec[i].second, vec[j].first,
                                 vec[j].second);
      if (!res.first) continue;
      long double X = res.second.first, Y = res.second.second;
      if (floor(X + eps) < X + 2 * eps && floor(X + eps) > X - 2 * eps) {
        if (floor(Y + eps) < Y + 2 * eps && floor(Y + eps) > Y - 2 * eps) {
          mp[{floor(X + eps), floor(Y + eps)}]++;
        }
      }
    }
  }
  for (auto p : mp) {
    long long k = 2;
    while (k * (k - 1) / 2 <= p.second) {
      if (k * (k - 1) / 2 == p.second) {
        ans -= (k - 1);
        break;
      }
      ++k;
    }
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
