#include
#define ll long long
using namespace std;
struct Point{
ll x,y;
Point(ll x=0,ll y=0):x(x),y(y){};
};
ll gcd(ll a,ll b)
{
return a==0?b:gcd(b%a,a);
}
bool cheak(ll op1,ll a,ll b){
if(a>b)
swap(a,b);
return op1>=a&&op1<=b;
}
Point point_of_intersection(Point f1,Point f2,Point f3,Point f4,bool &mark)
{
ll a1,a2,b1,b2,c1,c2,c3,c4,D,D1,D2;
a1=f2.y-f1.y;
a2=f1.x-f2.x;
b1=a1*f1.x+a2*f1.y;
///b1=(y2-y1)*x1+(x1-x2)*y1
c1=f4.y-f3.y;
c2=f3.x-f4.x;
b2=c1*f3.x+c2*f3.y;
///b2=(y4-y3)*x3+(x3-x4)*y3
c3=f2.x-f1.x;
c4=f4.x-f3.x;
D=c3*c1-c4*a1;
Point res;
if(D==0){
mark=false;
return res;
}
D1=b2*c3-b1*c4;
if(D1%D){
mark=false;
return res;
}
res.x=int(D1/D);
D2=b2*a1-b1*c1;
if(D2%D){
mark=false;
return res;
}
res.y=int(D2/D);
if(!cheak(res.x,f1.x,f2.x)||!cheak(res.x,f3.x,f4.x)){
mark=false; return res;
}
if(!cheak(res.y,f1.y,f2.y)||!cheak(res.y,f3.y,f4.y)){
mark=false; return res;
}
return res;
}
Point edge[1006][2];
int main()
{
int n;
while( ~scanf("%d",&n)){
for(int i=1;i<=n;i++){
scanf("%lld%lld%lld%lld",&edge[i][0].x,&edge[i][0].y,&edge[i][1].x,&edge[i][1].y);
}
set > re;
long long ans=0,tmp;
bool mark;
for(int i=1;i<=n;i++){
tmp=gcd(abs(edge[i][0].x-edge[i][1].x),abs(edge[i][0].y-edge[i][1].y))+1;
re.clear();
for(int j=1;j
mark=true;
Point res=point_of_intersection(edge[i][0],edge[i][1],edge[j][0],edge[j][1],mark);
if(mark)
re.insert(make_pair(res.x,res.y));
}
ans+=tmp-re.size();
}
printf("%lld\n",ans);
}
return 0;
}