#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
long long int points[1000000][2]={{0}};
int num=0;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int nump(int ax,int ay,int bx, int by,double m0,int m1){
    if(m0==1e8){return abs(by-ay)+1;}
    if(m0==0){return abs(bx-ax)+1;}
    return (abs(bx-ax))/m1+1;
}

int intsec(int a1x,int a1y,int b1x,int b1y,int a2x,int a2y,int b2x,int b2y,double m10,int m11,double m20,int m21){
    double y,x,temp;
    int check=0;
    if(m10==m20){
        check=0;
    }
    else if(m10!=1e8 && m20!=1e8){
        y=(a1y*m20-a2y*m10+m10*m20*(a2x-a1x))/(double)(m20-m10);//cout<<y<<endl;
        if(m10!=0){
            x=(double)(y-a1y)/(double)m10+a1x;
        }
        else{
            x=(double)(y-a2y)/(double)m20+a2x;
        }
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-13 && abs(y-(int)y)<=1e-13){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m10==1e8 && m20!=1e8){
        x=(double)a1x;
        y=(double)a2y+m20*(x-a2x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-13 && abs(y-(int)y)<=1e-13){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m20==1e8 && m10!=1e8){
        x=(double)a2x;
        y=(double)a1y+m10*(x-a1x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0  && abs(x-(int)x)<=1e-13 && abs(y-(int)y)<=1e-13){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }return check;
}

long long int correct(long long int points[][2], int num){
    long long int temp[num][3]={{0}},correctness1=0,correctness2=0;
    int count=0,check=0,index=0;;
    for(int i=0; i<num; i++){
        for(int j=0; j<count; j++){
            if(points[i][0]==temp[j][0] && points[i][1]==temp[j][1]){
                check=1;index=j;
            }
        }
        if(check==1){
            temp[index][2]++;
        }
        else{
           temp[count][0]=points[i][0];
           temp[count][1]=points[i][1];
           temp[count][2]++;count++;
        }
    }
    for(int i=0; i<count; i++){
        if(temp[i][2]!=1){
            correctness1+=(sqrt(1+8*temp[i][2])-1)/2.;
            correctness2+=temp[i][2];
        }
    }
    return correctness2-correctness1;
}

int main() {
	int n;
	cin>>n;
	int a[n][2],b[n][2],c;long double m[n][2];
	for(int i=0; i<n; i++){
	    cin>>a[i][0]>>a[i][1]>>b[i][0]>>b[i][1];
	    if(b[i][0]!=a[i][0]){
	    m[i][0]=(double)(b[i][1]-a[i][1])/(double)(b[i][0]-a[i][0]);}
	    else{
	        m[i][0]=1e8;
	    }
	    m[i][1]=abs(b[i][0]-a[i][0])/gcd(abs(b[i][1]-a[i][1]),abs(b[i][0]-a[i][0]));
	}

	long long int sum=0,sub=0;
	for(int i=0; i<n; i++){
	    sum+=nump(a[i][0],a[i][1],b[i][0],b[i][1],m[i][0],m[i][1]);//cout<<a[i][0]<<" "<<a[i][1]<<" "<<b[i][0]<<" "<<b[i][1]<<" "<<m[i][0]<<" "<<m[i][1]<<" "<<sum<<endl;
	}
	for(int i=0; i<n; i++){
	    for(int j=i+1; j<n; j++){
	        sub+=intsec(a[i][0],a[i][1],b[i][0],b[i][1],a[j][0],a[j][1],b[j][0],b[j][1],m[i][0],m[i][1],m[j][0],m[j][1]);
	    }//cout<<sub<<endl;
	}
	c=correct(points,num);
//	cout<<sum<<" "<<sub<<" "<<c<<endl;
	cout<<sum-sub+c<<endl;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
long double points[1000000][2]={{0}};
int num=0;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int nump(int ax,int ay,int bx, int by,double m0,int m1){
    if(m0==1e8){return abs(by-ay)+1;}
    if(m0==0){return abs(bx-ax)+1;}
    return (abs(bx-ax))/m1+1;
}

int intsec(int a1x,int a1y,int b1x,int b1y,int a2x,int a2y,int b2x,int b2y,long double m10,int m11,long double m20,int m21){
    long double y,x,temp;
    int check=0;
    if(m10==m20){
        check=0;
    }
    else if(m10!=1e8 && m20!=1e8){
        y=(a1y*m20-a2y*m10+m10*m20*(a2x-a1x))/(long double)(m20-m10);//cout<<y<<endl;
        if(abs(m10)>=1e-4){
            x=(long double)(y-a1y)/(double)m10+a1x;
        }
        else{
            x=(long double)(y-a2y)/(double)m20+a2x;
        }
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m10==1e8 && m20!=1e8){
        x=(double)a1x;
        y=(double)a2y+m20*(x-a2x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m20==1e8 && m10!=1e8){
        x=(double)a2x;
        y=(double)a1y+m10*(x-a1x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0  && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }return check;
}

long long int correct(long double points[][2], int num){
    long double temp[num][3]={{0}},correctness1=0,correctness2=0;
    int count=0,check=0,index=0;;
    for(int i=0; i<num; i++){
        for(int j=0; j<count; j++){
            if(points[i][0]<temp[j][0]+1e-8  && points[i][0]>temp[j][0]-(1e-8) && points[i][1]>temp[j][1]-(1e-8) && points[i][1]<temp[j][1]+1e-8){
                check=1;index=j;
            }
        }
        if(check==1){
            temp[index][2]++;
        }
        else{
           temp[count][0]=points[i][0];
           temp[count][1]=points[i][1];
           temp[count][2]++;count++;
        }
    }//cout<<temp[count-1][2]<<endl;
    for(int i=0; i<count; i++){
        if(temp[i][2]!=1){
            correctness1+=(sqrt(1+8*temp[i][2])-1)/2.;
            correctness2+=temp[i][2];
        }
    }
    return correctness2-correctness1;
}

int main() {
	int n;
	cin>>n;
	int a[n][2],b[n][2],c;long double m[n][2];
	for(int i=0; i<n; i++){
	    cin>>a[i][0]>>a[i][1]>>b[i][0]>>b[i][1];
	    if(b[i][0]!=a[i][0]){
	    m[i][0]=(double)(b[i][1]-a[i][1])/(double)(b[i][0]-a[i][0]);}
	    else{
	        m[i][0]=1e8;
	    }
	    m[i][1]=abs(b[i][0]-a[i][0])/gcd(abs(b[i][1]-a[i][1]),abs(b[i][0]-a[i][0]));
	}

	long long int sum=0,sub=0;
	for(int i=0; i<n; i++){
	    sum+=nump(a[i][0],a[i][1],b[i][0],b[i][1],m[i][0],m[i][1]);//cout<<a[i][0]<<" "<<a[i][1]<<" "<<b[i][0]<<" "<<b[i][1]<<" "<<m[i][0]<<" "<<m[i][1]<<" "<<sum<<endl;
	}
	for(int i=0; i<n; i++){
	    for(int j=i+1; j<n; j++){
	        sub+=intsec(a[i][0],a[i][1],b[i][0],b[i][1],a[j][0],a[j][1],b[j][0],b[j][1],m[i][0],m[i][1],m[j][0],m[j][1]);
	    }//cout<<sub<<endl;
	}
	c=correct(points,num);
	cout<<sum<<" "<<sub<<" "<<c<<endl;
	cout<<sum-sub+c<<endl;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
long double points[1000000][2]={{0}};
int num=0;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int nump(int ax,int ay,int bx, int by,double m0,int m1){
    if(m0==1e8){return abs(by-ay)+1;}
    if(m0==0){return abs(bx-ax)+1;}
    return (abs(bx-ax))/m1+1;
}

int intsec(int a1x,int a1y,int b1x,int b1y,int a2x,int a2y,int b2x,int b2y,double m10,int m11,double m20,int m21){
    double y,x,temp;
    int check=0;
    if(m10==m20){
        check=0;
    }
    else if(m10!=1e8 && m20!=1e8){
        y=(a1y*m20-a2y*m10+m10*m20*(a2x-a1x))/(double)(m20-m10);//cout<<y<<endl;
        if(m10!=0){
            x=(double)(y-a1y)/(double)m10+a1x;
        }
        else{
            x=(double)(y-a2y)/(double)m20+a2x;
        }
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m10==1e8 && m20!=1e8){
        x=(double)a1x;
        y=(double)a2y+m20*(x-a2x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m20==1e8 && m10!=1e8){
        x=(double)a2x;
        y=(double)a1y+m10*(x-a1x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0  && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }return check;
}

long long int correct(long double points[][2], int num){
    long double temp[num][3]={{0}},correctness1=0,correctness2=0;
    int count=0,check=0,index=0;;
    for(int i=0; i<num; i++){
        for(int j=0; j<count; j++){
            if(points[i][0]==temp[j][0] && points[i][1]==temp[j][1]){
                check=1;index=j;
            }
        }
        if(check==1){
            temp[index][2]++;
        }
        else{
           temp[count][0]=points[i][0];
           temp[count][1]=points[i][1];
           temp[count][2]++;count++;
        }
    }
    for(int i=0; i<count; i++){
        if(temp[i][2]!=1){
            correctness1+=(sqrt(1+8*temp[i][2])-1)/2.;
            correctness2+=temp[i][2];
        }
    }
    return correctness2-correctness1;
}

int main() {
	int n;
	cin>>n;
	int a[n][2],b[n][2],c;long double m[n][2];
	for(int i=0; i<n; i++){
	    cin>>a[i][0]>>a[i][1]>>b[i][0]>>b[i][1];
	    if(b[i][0]!=a[i][0]){
	    m[i][0]=(double)(b[i][1]-a[i][1])/(double)(b[i][0]-a[i][0]);}
	    else{
	        m[i][0]=1e8;
	    }
	    m[i][1]=abs(b[i][0]-a[i][0])/gcd(abs(b[i][1]-a[i][1]),abs(b[i][0]-a[i][0]));
	}

	long long int sum=0,sub=0;
	for(int i=0; i<n; i++){
	    sum+=nump(a[i][0],a[i][1],b[i][0],b[i][1],m[i][0],m[i][1]);//cout<<a[i][0]<<" "<<a[i][1]<<" "<<b[i][0]<<" "<<b[i][1]<<" "<<m[i][0]<<" "<<m[i][1]<<" "<<sum<<endl;
	}
	for(int i=0; i<n; i++){
	    for(int j=i+1; j<n; j++){
	        sub+=intsec(a[i][0],a[i][1],b[i][0],b[i][1],a[j][0],a[j][1],b[j][0],b[j][1],m[i][0],m[i][1],m[j][0],m[j][1]);
	    }//cout<<sub<<endl;
	}
	c=correct(points,num);
//	cout<<sum<<" "<<sub<<" "<<c<<endl;
	cout<<sum-sub+c<<endl;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
long double points[1000000][2]={{0}};
int num=0;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int nump(int ax,int ay,int bx, int by,double m0,int m1){
    if(m0==1e8){return abs(by-ay)+1;}
    if(m0==0){return abs(bx-ax)+1;}
    return (abs(bx-ax))/m1+1;
}

int intsec(int a1x,int a1y,int b1x,int b1y,int a2x,int a2y,int b2x,int b2y,long double m10,int m11,long double m20,int m21){
    long double y,x,temp;
    int check=0;
    if(m10==m20){
        check=0;
    }
    else if(m10!=1e8 && m20!=1e8){
        y=(a1y*m20-a2y*m10+m10*m20*(a2x-a1x))/(long double)(m20-m10);//cout<<y<<endl;
        if(m10!=0){
            x=(long double)(y-a1y)/(double)m10+a1x;
        }
        else{
            x=(long double)(y-a2y)/(double)m20+a2x;
        }
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m10==1e8 && m20!=1e8){
        x=(double)a1x;
        y=(double)a2y+m20*(x-a2x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m20==1e8 && m10!=1e8){
        x=(double)a2x;
        y=(double)a1y+m10*(x-a1x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0  && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }return check;
}

long long int correct(long double points[][2], int num){
    long double temp[num][3]={{0}},correctness1=0,correctness2=0;
    int count=0,check=0,index=0;;
    for(int i=0; i<num; i++){
        for(int j=0; j<count; j++){
            if(points[i][0]<temp[j][0]+1e-8  && points[i][0]>temp[j][0]-(1e-8) && points[i][1]>temp[j][1]-(1e-8) && points[i][1]<temp[j][1]+1e-8){
                check=1;index=j;
            }
        }
        if(check==1){
            temp[index][2]++;
        }
        else{
           temp[count][0]=points[i][0];
           temp[count][1]=points[i][1];
           temp[count][2]++;count++;
        }
    }//cout<<temp[count-1][2]<<endl;
    for(int i=0; i<count; i++){
        if(temp[i][2]!=1){
            correctness1+=(sqrt(1+8*temp[i][2])-1)/2.;
            correctness2+=temp[i][2];
        }
    }
    return correctness2-correctness1;
}

int main() {
	int n;
	cin>>n;
	int a[n][2],b[n][2],c;long double m[n][2];
	for(int i=0; i<n; i++){
	    cin>>a[i][0]>>a[i][1]>>b[i][0]>>b[i][1];
	    if(b[i][0]!=a[i][0]){
	    m[i][0]=(double)(b[i][1]-a[i][1])/(double)(b[i][0]-a[i][0]);}
	    else{
	        m[i][0]=1e8;
	    }
	    m[i][1]=abs(b[i][0]-a[i][0])/gcd(abs(b[i][1]-a[i][1]),abs(b[i][0]-a[i][0]));
	}

	long long int sum=0,sub=0;
	for(int i=0; i<n; i++){
	    sum+=nump(a[i][0],a[i][1],b[i][0],b[i][1],m[i][0],m[i][1]);//cout<<a[i][0]<<" "<<a[i][1]<<" "<<b[i][0]<<" "<<b[i][1]<<" "<<m[i][0]<<" "<<m[i][1]<<" "<<sum<<endl;
	}
	for(int i=0; i<n; i++){
	    for(int j=i+1; j<n; j++){
	        sub+=intsec(a[i][0],a[i][1],b[i][0],b[i][1],a[j][0],a[j][1],b[j][0],b[j][1],m[i][0],m[i][1],m[j][0],m[j][1]);
	    }//cout<<sub<<endl;
	}
	c=correct(points,num);
//	cout<<sum<<" "<<sub<<" "<<c<<endl;
	cout<<sum-sub+c<<endl;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
long long int points[1000000][2]={{0}};
int num=0;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int nump(int ax,int ay,int bx, int by,double m0,int m1){
    if(m0==1e8){return abs(by-ay)+1;}
    if(m0==0){return abs(bx-ax)+1;}
    return (abs(bx-ax))/m1+1;
}

int intsec(int a1x,int a1y,int b1x,int b1y,int a2x,int a2y,int b2x,int b2y,int m10,int m11,int m20,int m21){
    double y,x,temp;
    int check=0;
    if(m10==m20){
        check=0;
    }
    else if(m10!=1e8 && m20!=1e8){
        y=(a1y*m20-a2y*m10+m10*m20*(a2x-a1x))/(double)(m20-m10);
        if(m10!=0){
            x=(y-a1y)/(double)m10+a1x;
        }
        else{
            x=(y-a2y)/(double)m20+a2x;
        }
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-14 && abs(y-(int)y)<=1e-14){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m10==1e8 && m20!=1e8){
        x=(double)a1x;
        y=(double)a2y+m20*(x-a2x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-14 && abs(y-(int)y)<=1e-14){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m20==1e8 && m10!=1e8){
        x=(double)a2x;
        y=(double)a1y+m10*(x-a1x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0  && abs(x-(int)x)<=1e-14 && abs(y-(int)y)<=1e-14){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }return check;
}

long long int correct(long long int points[][2], int num){
    long long int temp[num][3]={{0}},correctness1=0,correctness2=0;
    int count=0,check=0,index=0;;
    for(int i=0; i<num; i++){
        for(int j=0; j<count; j++){
            if(points[i][0]==temp[j][0] && points[i][1]==temp[j][1]){
                check=1;index=j;
            }
        }
        if(check==1){
            temp[index][2]++;
        }
        else{
           temp[count][0]=points[i][0];
           temp[count][1]=points[i][1];
           temp[count][2]++;count++;
        }
    }
    for(int i=0; i<count; i++){
        if(temp[i][2]!=1){
            correctness1+=(sqrt(1+8*temp[i][2])-1)/2.;
            correctness2+=temp[i][2];
        }
    }
    return correctness2-correctness1;
}

int main() {
	int n;
	cin>>n;
	int a[n][2],b[n][2],c;long double m[n][2];
	for(int i=0; i<n; i++){
	    cin>>a[i][0]>>a[i][1]>>b[i][0]>>b[i][1];
	    if(b[i][0]!=a[i][0]){
	    m[i][0]=(float)(b[i][1]-a[i][1])/(float)(b[i][0]-a[i][0]);}
	    else{
	        m[i][0]=1e8;
	    }
	    m[i][1]=abs(b[i][0]-a[i][0])/gcd(abs(b[i][1]-a[i][1]),abs(b[i][0]-a[i][0]));
	}

	long long int sum=0,sub=0;
	for(int i=0; i<n; i++){
	    sum+=nump(a[i][0],a[i][1],b[i][0],b[i][1],m[i][0],m[i][1]);//cout<<a[i][0]<<" "<<a[i][1]<<" "<<b[i][0]<<" "<<b[i][1]<<" "<<m[i][0]<<" "<<m[i][1]<<" "<<sum<<endl;
	}
	for(int i=0; i<n; i++){
	    for(int j=i+1; j<n; j++){
	        sub+=intsec(a[i][0],a[i][1],b[i][0],b[i][1],a[j][0],a[j][1],b[j][0],b[j][1],m[i][0],m[i][1],m[j][0],m[j][1]);
	    }
	}
	c=correct(points,num);
//	cout<<sum<<" "<<sub<<" "<<c<<endl;
	cout<<sum-sub+c<<endl;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
long long int points[1000000][2]={{0}};
int num=0;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int nump(int ax,int ay,int bx, int by,double m0,int m1){
    if(m0==1e8){return abs(by-ay)+1;}
    if(m0==0){return abs(bx-ax)+1;}
    return (abs(bx-ax))/m1+1;
}

int intsec(int a1x,int a1y,int b1x,int b1y,int a2x,int a2y,int b2x,int b2y,double m10,int m11,double m20,int m21){
    double y,x,temp;
    int check=0;
    if(m10==m20){
        check=0;
    }
    else if(m10!=1e8 && m20!=1e8){
        y=(a1y*m20-a2y*m10+m10*m20*(a2x-a1x))/(double)(m20-m10);//cout<<y<<endl;
        if(m10!=0){
            x=(double)(y-a1y)/(double)m10+a1x;
        }
        else{
            x=(double)(y-a2y)/(double)m20+a2x;
        }
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m10==1e8 && m20!=1e8){
        x=(double)a1x;
        y=(double)a2y+m20*(x-a2x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m20==1e8 && m10!=1e8){
        x=(double)a2x;
        y=(double)a1y+m10*(x-a1x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0  && abs(x-(int)x)<=1e-6 && abs(y-(int)y)<=1e-6){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }return check;
}

long long int correct(long long int points[][2], int num){
    long long int temp[num][3]={{0}},correctness1=0,correctness2=0;
    int count=0,check=0,index=0;;
    for(int i=0; i<num; i++){
        for(int j=0; j<count; j++){
            if(points[i][0]==temp[j][0] && points[i][1]==temp[j][1]){
                check=1;index=j;
            }
        }
        if(check==1){
            temp[index][2]++;
        }
        else{
           temp[count][0]=points[i][0];
           temp[count][1]=points[i][1];
           temp[count][2]++;count++;
        }
    }
    for(int i=0; i<count; i++){
        if(temp[i][2]!=1){
            correctness1+=(sqrt(1+8*temp[i][2])-1)/2.;
            correctness2+=temp[i][2];
        }
    }
    return correctness2-correctness1;
}

int main() {
	int n;
	cin>>n;
	int a[n][2],b[n][2],c;long double m[n][2];
	for(int i=0; i<n; i++){
	    cin>>a[i][0]>>a[i][1]>>b[i][0]>>b[i][1];
	    if(b[i][0]!=a[i][0]){
	    m[i][0]=(double)(b[i][1]-a[i][1])/(double)(b[i][0]-a[i][0]);}
	    else{
	        m[i][0]=1e8;
	    }
	    m[i][1]=abs(b[i][0]-a[i][0])/gcd(abs(b[i][1]-a[i][1]),abs(b[i][0]-a[i][0]));
	}

	long long int sum=0,sub=0;
	for(int i=0; i<n; i++){
	    sum+=nump(a[i][0],a[i][1],b[i][0],b[i][1],m[i][0],m[i][1]);//cout<<a[i][0]<<" "<<a[i][1]<<" "<<b[i][0]<<" "<<b[i][1]<<" "<<m[i][0]<<" "<<m[i][1]<<" "<<sum<<endl;
	}
	for(int i=0; i<n; i++){
	    for(int j=i+1; j<n; j++){
	        sub+=intsec(a[i][0],a[i][1],b[i][0],b[i][1],a[j][0],a[j][1],b[j][0],b[j][1],m[i][0],m[i][1],m[j][0],m[j][1]);
	    }//cout<<sub<<endl;
	}
	c=correct(points,num);
//	cout<<sum<<" "<<sub<<" "<<c<<endl;
	cout<<sum-sub+c<<endl;

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
long long int points[1000000][2]={{0}};
int num=0;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int nump(int ax,int ay,int bx, int by,double m0,int m1){
    if(m0==1e8){return abs(by-ay)+1;}
    if(m0==0){return abs(bx-ax)+1;}
    return (abs(bx-ax))/m1+1;
}

int intsec(int a1x,int a1y,int b1x,int b1y,int a2x,int a2y,int b2x,int b2y,double m10,int m11,double m20,int m21){
    double y,x,temp;
    int check=0;
    if(m10==m20){
        check=0;
    }
    else if(m10!=1e8 && m20!=1e8){
        y=((double)a1y*m20-a2y*m10+m10*m20*(a2x-a1x))/(double)(m20-m10);
        if(m10!=0){
            x=(double)(y-a1y)/(double)m10+a1x;
        }
        else{
            x=(double)(y-a2y)/(double)m20+a2x;
        }
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-14 && abs(y-(int)y)<=1e-14){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m10==1e8 && m20!=1e8){
        x=(double)a1x;
        y=(double)a2y+m20*(x-a2x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0 && abs(x-(int)x)<=1e-14 && abs(y-(int)y)<=1e-14){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }
    else if(m20==1e8 && m10!=1e8){
        x=(double)a2x;
        y=(double)a1y+m10*(x-a1x);
        if((a1x-x)*(b1x-x)<=0 && (a2x-x)*(b2x-x)<=0 && (a1y-y)*(b1y-y)<=0 && (a2y-y)*(b2y-y)<=0  && abs(x-(int)x)<=1e-14 && abs(y-(int)y)<=1e-14){
            check=1;points[num][0]=x;points[num][1]=y;num++;
        }
    }return check;
}

long long int correct(long long int points[][2], int num){
    long long int temp[num][3]={{0}},correctness1=0,correctness2=0;
    int count=0,check=0,index=0;;
    for(int i=0; i<num; i++){
        for(int j=0; j<count; j++){
            if(points[i][0]==temp[j][0] && points[i][1]==temp[j][1]){
                check=1;index=j;
            }
        }
        if(check==1){
            temp[index][2]++;
        }
        else{
           temp[count][0]=points[i][0];
           temp[count][1]=points[i][1];
           temp[count][2]++;count++;
        }
    }
    for(int i=0; i<count; i++){
        if(temp[i][2]!=1){
            correctness1+=(sqrt(1+8*temp[i][2])-1)/2.;
            correctness2+=temp[i][2];
        }
    }
    return correctness2-correctness1;
}

int main() {
	int n;
	cin>>n;
	int a[n][2],b[n][2],c;long double m[n][2];
	for(int i=0; i<n; i++){
	    cin>>a[i][0]>>a[i][1]>>b[i][0]>>b[i][1];
	    if(b[i][0]!=a[i][0]){
	    m[i][0]=(float)(b[i][1]-a[i][1])/(float)(b[i][0]-a[i][0]);}
	    else{
	        m[i][0]=1e8;
	    }
	    m[i][1]=abs(b[i][0]-a[i][0])/gcd(abs(b[i][1]-a[i][1]),abs(b[i][0]-a[i][0]));
	}

	long long int sum=0,sub=0;
	for(int i=0; i<n; i++){
	    sum+=nump(a[i][0],a[i][1],b[i][0],b[i][1],m[i][0],m[i][1]);//cout<<a[i][0]<<" "<<a[i][1]<<" "<<b[i][0]<<" "<<b[i][1]<<" "<<m[i][0]<<" "<<m[i][1]<<" "<<sum<<endl;
	}
	for(int i=0; i<n; i++){
	    for(int j=i+1; j<n; j++){
	        sub+=intsec(a[i][0],a[i][1],b[i][0],b[i][1],a[j][0],a[j][1],b[j][0],b[j][1],m[i][0],m[i][1],m[j][0],m[j][1]);
	    }//cout<<sub<<endl;
	}
	c=correct(points,num);
//	cout<<sum<<" "<<sub<<" "<<c<<endl;
	cout<<sum-sub+c<<endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <set>

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    int A, B, C;
    line(int AA = 0, int BB = 0, int CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

int abs(int x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long double dst(long long x1, long long y1, long long x2, long long y2) {
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    long double cur_dst = dst(a.x1, a.y1, a.x2, a.y2);
    if (a.x1 > 10000000) exit(41);
    if (a.x1 < -10000000) exit(41);
    if (cur_dst < dst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = dst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < dst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

int main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <set>

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    int A, B, C;
    line(int AA = 0, int BB = 0, int CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

int abs(int x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long double dst(long long x1, long long y1, long long x2, long long y2) {
    //if (x1 - x2 > 10000000) exit(41);
    //if (x1 - x2 < -10000000) exit(41);
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    if ((p.x < -1000000) || (p.x > 1000000))
        return false;
    if ((p.y < -1000000) || (p.y > 1000000))
        return false;

    long double cur_dst = dst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < dst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = dst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < dst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

int main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <set>

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    int A, B, C;
    line(int AA = 0, int BB = 0, int CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

int abs(int x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long double dst(long long x1, long long y1, long long x2, long long y2) {
    if (x1 - x2 > 10000000) exit(41);
    if (x1 - x2 < -10000000) exit(41);
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    long double cur_dst = dst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < dst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = dst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < dst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

int main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <set>

#define int long long
using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    int A, B, C;
    line(int AA = 0, int BB = 0, int CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}
/*
int abs(int x) {
    return x < 0 ? -x : x;
}
*/
bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long long sqrdst(long long x1, long long y1, long long x2, long long y2) {
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    long long cur_dst = sqrdst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < sqrdst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = sqrdst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < sqrdst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    ll A, B, C;
    line(ll AA = 0, ll BB = 0, ll CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(ll x1, ll y1, ll x2, ll y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    ll x1, y1, x2, y2; line l;
    line_segment(ll X1 = 0, ll Y1 = 0, ll X2 = 0, ll Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

ll absf(ll x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long long sqrdst(long long x1, long long y1, long long x2, long long y2) {
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    long long cur_dst = sqrdst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < sqrdst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = sqrdst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < sqrdst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
ll ans = 0;

int main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(absf(a[i].l.A), absf(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <set>

#define int long long
using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    int A, B, C;
    line(int AA = 0, int BB = 0, int CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

int abs(int x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long long sqrdst(long long x1, long long y1, long long x2, long long y2) {
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    long long cur_dst = sqrdst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < sqrdst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = sqrdst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < sqrdst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    long long A, B, C;
    line(long long AA = 0, long long BB = 0, long long CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = 1LL * x1 * y2 - 1LL * x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

int abs(int x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = a.A * b.C - b.A * a.C;
    long long u2 = b.A * a.B - a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long long sqrdst(long long x1, long long y1, long long x2, long long y2) {
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    if ((p.x < -1000000) || (p.x > 1000000))
        return false;
    if ((p.y < -1000000) || (p.y > 1000000))
        return false;

    long long cur_dst = sqrdst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < sqrdst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = sqrdst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < sqrdst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

int main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <set>

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    int A, B, C;
    line(int AA = 0, int BB = 0, int CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

int abs(int x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long long sqrdst(long long x1, long long y1, long long x2, long long y2) {
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    long long cur_dst = sqrdst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < sqrdst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = sqrdst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < sqrdst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < sqrdst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

int main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <set>

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    int A, B, C;
    line(int AA = 0, int BB = 0, int CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

int abs(int x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long double dst(long long x1, long long y1, long long x2, long long y2) {
    if (x1 > 10000000) exit(41);
    if (x1 < -10000000) exit(41);
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    long double cur_dst = dst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < dst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = dst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < dst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

int main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

struct line {
    int A, B, C;
    line(int AA = 0, int BB = 0, int CC = 0) :
        A(AA), B(BB), C(CC) {}
    line(int x1, int y1, int x2, int y2) {
        A = y1 - y2;
        B = x2 - x1;
        C = x1 * y2 - x2 * y1;
    }
};

bool operator <(const line& a, const line& b) {
    if (a.A < b.A) return true;
    if (a.A > b.A) return false;
    if (a.B < b.B) return true;
    if (a.B > b.B) return false;
    if (a.C < b.C) return true;
    if (a.C > b.C) return false;
    return false;
}

struct line_segment {
    int x1, y1, x2, y2; line l;
    line_segment(int X1 = 0, int Y1 = 0, int X2 = 0, int Y2 = 0) :
        x1(X1), y1(Y1), x2(X2), y2(Y2), l(X1, Y1, X2, Y2) {}
};

bool operator <(const line_segment& a, const line_segment& b) {
    if (a.x1 < b.x1) return true;
    if (a.x1 > b.x1) return false;
    if (a.y1 < b.y1) return true;
    if (a.y1 > b.y1) return false;
    if (a.x2 < b.x2) return true;
    if (a.x2 > b.x2) return false;
    if (a.y2 < b.y2) return true;
    if (a.y2 > b.y2) return false;
    return a.l < b.l;
}

struct point {
    long long x, y;
    point(long long X = 0, long long Y = 0) :
        x(X), y(Y) {}
};

bool operator <(const point& a, const point& b) {
    if (a.x < b.x) return true;
    if (a.x > b.x) return false;
    if (a.y < b.y) return true;
    if (a.y > b.y) return false;
    return false;
}

bool operator ==(const point& a, const point& b) {
    return (a.x == b.x) && (a.y == b.y);
}

int abs(int x) {
    return x < 0 ? -x : x;
}

bool can_get_y(line a, line b, long long& Y) {
    long long u1 = 1LL * a.A * b.C - 1LL * b.A * a.C;
    long long u2 = 1LL * b.A * a.B - 1LL * a.A * b.B;
    //cout << "Y : " << u1 << " " << u2 << "\n";
    if ((u2) && (u1 % u2 == 0)) {
        Y = u1 / u2;
        return true;
    }
    return false;
}

bool can_get_x(line a, line b, long long Y, long long& X) {
    long long u1 = -1LL * a.B * Y - a.C;
    long long u2 = 1LL * a.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    u1 = -1LL * b.B * Y - b.C;
    u2 = 1LL * b.A;
    if ((u2) && (u1 % u2 == 0)) {
        X = u1 / u2;
        return true;
    }
    return false;
}

long double dst(long long x1, long long y1, long long x2, long long y2) {
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

bool point_in_line_segment(line_segment a, line_segment b, point p) {
    long double cur_dst = dst(a.x1, a.y1, a.x2, a.y2);
    if (cur_dst < dst(a.x1, a.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(a.x2, a.y2, p.x, p.y))
        return false;

    cur_dst = dst(b.x1, b.y1, b.x2, b.y2);
    if (cur_dst < dst(b.x1, b.y1, p.x, p.y))
        return false;
    if (cur_dst < dst(b.x2, b.y2, p.x, p.y))
        return false;
    return true;
}

bool have_common_point(line_segment a, line_segment b, point& p) {

    if (can_get_y(a.l, b.l, p.y)) {
        if (can_get_x(a.l, b.l, p.y, p.x)) {
            if (point_in_line_segment(a, b, p))
                return true;
        }
    }
    return false;
}

vector <line_segment> a;
set < pair <point, line_segment> > common_point;
set < pair <point, line_segment> > :: iterator it;
int n;
int ans = 0;

int main() {
    cin >> n; a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
        a[i].l = line(a[i].x1, a[i].y1, a[i].x2, a[i].y2);
    }
/*
    for (int i = 0; i < n; i++) {
        cout << i << " : ";
        cout << a[i].x1 << " " << a[i].y1 << " ";
        cout << a[i].x2 << " " << a[i].y2 << " | ";
        cout << a[i].l.A << " " << a[i].l.B << " " << a[i].l.C << "\n";
    }
*/
    for (int i = 0; i < n; i++)
        ans += gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1;
/*
    for (int i = 0; i < n; i++)
        cout << i << " : " << gcd(abs(a[i].l.A), abs(a[i].l.B)) + 1 << "\n";
    cout << ans << "\n";
*/
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            point p;
            //cout << i << " " << j << endl;
            if (have_common_point(a[i], a[j], p)) {
                //cout << "!OK : " << p.x << " " << p.y << " | " << i << " " << j << "\n";
                common_point.insert(make_pair(p, a[i]));
                common_point.insert(make_pair(p, a[j]));
            }
        }
    }
/*
    for (it = common_point.begin(); it != common_point.end(); it++) {
        cout << it->first.x << " " << it->first.y << " | ";
        cout << it->second.x1 << " " << it->second.y1 << " ";
        cout << it->second.x2 << " " << it->second.y2 << " | ";
        cout << it->second.l.A << " " << it->second.l.B << " " << it->second.l.C << "\n";
    }
*/
    //cout << "kokoko" << "\n";

    for (it = common_point.begin(); it != common_point.end(); ) {
        point cur_p = it->first; int cnt = 0;
        while ((it != common_point.end()) && (cur_p == it->first))
            it++, cnt++;
        ans -= cnt - 1;
    }
    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  if (!b) {
    return a;
  }
  return gcd(b, a % b);
}
struct pair_hash {
  template <typename T, typename U>
  size_t operator()(const pair<T, U> &x) const {
    return hash<T>()(x.first) ^ (1317 + hash<T>()(x.second) << 1);
  }
};
struct Point {
  Point(ll x, ll y) : x(x), y(y) {}
  Point() {}
  ll x;
  ll y;
};
struct Segment {
  Segment(ll x1, ll y1, ll x2, ll y2) {
    if (x1 < x2 || x1 == x2 && y1 < y2) {
      A = Point(x1, y1);
      B = Point(x2, y2);
    } else {
      A = Point(x2, y2);
      B = Point(x1, y1);
    }
    CalculateSlope();
    length = hypot(1.0 * (B.x - A.x), 1.0 * (B.y - A.y));
    a = B.y - A.y;
    b = A.x - B.x;
    c = A.y * B.x - A.x * B.y;
  }

  void CalculateSlope() {
    ll g = gcd(abs(B.x - A.x), abs(B.y - A.y));
    slope.first = (B.x - A.x) / g;
    slope.second = (B.y - A.y) / g;
  }
  bool Parallel(const Segment &another) const { return slope == another.slope; }
  bool Horizontal() const { return A.y == B.y; }
  bool Vertical() const { return A.x == B.x; }
  bool IntersectAtIntegerPoint(const Segment &another, Point &pt) const {
    if (Parallel(another)) {
      return false; // input is guaranteed no same line
    }
    ll den = a * another.b - b * another.a;
    ll num1 = -c * another.b + another.c * b;
    ll num2 = c * another.a - another.c * a;
    if (num2 % den || num1 % den) {
      return false;
    }
    pt.x = num1 / den;
    pt.y = num2 / den;
    if (pt.x >= A.x && pt.x <= B.x)
      return true;
    return false;
  }
  ll Count() const {
    ll g = gcd(abs(B.x - A.x), abs(B.y - A.y));
    return 1LL + min(abs(B.x - A.x), abs(B.y - A.y)) / g;
  }
  pair<ll, ll> slope;
  double length;
  Point A;
  Point B;
  ll a, b, c;
};
class Solver {
public:
  void solve() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    Point pt;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      temp_segs.emplace_back(x1, y1, x2, y2);
      auto &cur = temp_segs.back();
      ans += cur.Count();
      unordered_set<pair<ll, ll>, pair_hash> st;
      for (int j = 0; j < i; j++) {
        if (cur.IntersectAtIntegerPoint(temp_segs[j], pt)) {
          st.insert(pt);
        }
      }
      for (auto &ele : st) {
        count[ele]++;
      }
    }
    for (auto &pa : count) {
      ans -= pa.second;
    }
    cout << ans << endl;
  }
  vector<Segment> temp_segs;
  int n;
  unordered_map<pair<ll, ll>, int, pair_hash> count;
};
int main() {
  Solver sol;
  sol.solve();
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  if (!b) {
    return a;
  }
  return gcd(b, a % b);
}
struct pair_hash {
  template <typename T, typename U>
  size_t operator()(const pair<T, U> &x) const {
    return hash<T>()(x.first) ^ (1317 + hash<T>()(x.second) << 1);
  }
};
struct Point {
  Point(ll x, ll y) : x(x), y(y) {}
  Point() {}
  ll x;
  ll y;
};
struct Segment {
  Segment(ll x1, ll y1, ll x2, ll y2) {
    if (x1 < x2 || x1 == x2 && y1 < y2) {
      A = Point(x1, y1);
      B = Point(x2, y2);
    } else {
      A = Point(x2, y2);
      B = Point(x1, y1);
    }
    CalculateSlope();
    length = hypot(1.0 * (B.x - A.x), 1.0 * (B.y - A.y));
    a = B.y - A.y;
    b = A.x - B.x;
    c = A.y * B.x - A.x * B.y;
  }

  void CalculateSlope() {
    ll g = gcd(abs(B.x - A.x), abs(B.y - A.y));
    slope.first = (B.x - A.x) / g;
    slope.second = (B.y - A.y) / g;
  }
  bool Parallel(const Segment &another) const { return slope == another.slope; }
  bool Horizontal() const { return A.y == B.y; }
  bool Vertical() const { return A.x == B.x; }
  bool Contain(const Point &pt) const {
    if (Vertical()) {
      return pt.y >= A.y && pt.y <= B.y;
    }
    return pt.x >= A.x && pt.x <= B.x;
  }
  bool IntersectAtIntegerPoint(const Segment &another, Point &pt) const {
    if (Parallel(another)) {
      return false; // input is guaranteed no same line
    }
    ll den = a * another.b - b * another.a;
    ll num1 = -c * another.b + another.c * b;
    ll num2 = c * another.a - another.c * a;
    if (num2 % den || num1 % den) {
      return false;
    }
    pt.x = num1 / den;
    pt.y = num2 / den;
    if (Contain(pt) && another.Contain(pt))
      return true;
    return false;
  }
  ll Count() const {
    ll g = gcd(abs(B.x - A.x), abs(B.y - A.y));
    return 1LL + g;
  }
  pair<ll, ll> slope;
  double length;
  Point A;
  Point B;
  ll a, b, c;
};
class Solver {
public:
  void solve() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    Point pt;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      temp_segs.emplace_back(x1, y1, x2, y2);
      auto &cur = temp_segs.back();
      ans += cur.Count();
      unordered_set<pair<ll, ll>, pair_hash> st;
      for (int j = 0; j < i; j++) {
        if (cur.IntersectAtIntegerPoint(temp_segs[j], pt)) {
          st.emplace(pt.x, pt.y);
        }
      }
      for (auto &ele : st) {
        count[ele]++;
      }
    }
    for (auto &pa : count) {
      ans -= pa.second;
    }
    cout << ans << endl;
  }
  vector<Segment> temp_segs;
  int n;
  unordered_map<pair<ll, ll>, int, pair_hash> count;
};
int main() {
  Solver sol;
  sol.solve();
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  if (!b) {
    return a;
  }
  return gcd(b, a % b);
}
struct pair_hash {
  template <typename T, typename U>
  size_t operator()(const pair<T, U> &x) const {
    return hash<T>()(x.first) ^ (1317 + hash<T>()(x.second) << 1);
  }
};
struct Point {
  Point(ll x, ll y) : x(x), y(y) {}
  Point() {}
  ll x;
  ll y;
};
struct Segment {
  Segment(ll x1, ll y1, ll x2, ll y2) {
    if (x1 < x2 || x1 == x2 && y1 < y2) {
      A = Point(x1, y1);
      B = Point(x2, y2);
    } else {
      A = Point(x2, y2);
      B = Point(x1, y1);
    }
    CalculateSlope();
    length = hypot(1.0 * (B.x - A.x), 1.0 * (B.y - A.y));
    a = B.y - A.y;
    b = A.x - B.x;
    c = A.y * B.x - A.x * B.y;
  }

  void CalculateSlope() {
    ll g = gcd(abs(B.x - A.x), abs(B.y - A.y));
    slope.first = (B.x - A.x) / g;
    slope.second = (B.y - A.y) / g;
  }
  bool Parallel(const Segment &another) const { return slope == another.slope; }
  bool Horizontal() const { return A.y == B.y; }
  bool Vertical() const { return A.x == B.x; }
  bool IntersectAtIntegerPoint(const Segment &another, Point &pt) const {
    if (Parallel(another)) {
      return false; // input is guaranteed no same line
    }
    ll den = a * another.b - b * another.a;
    ll num1 = -c * another.b + another.c * b;
    ll num2 = c * another.a - another.c * a;
    if (num2 % den || num1 % den) {
      return false;
    }
    pt.x = num1 / den;
    pt.y = num2 / den;
    if (pt.x >= A.x && pt.x <= B.x)
      return true;
    return false;
  }
  ll Count() const {
    ll g = gdc(abs(B.x - A.x), abs(B.y - A.y));
    return 1LL + min(abs(B.x - A.x), abs(B.y - A.y)) / g;
  }
  pair<ll, ll> slope;
  double length;
  Point A;
  Point B;
  ll a, b, c;
};
class Solver {
public:
  void solve() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    Point pt;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      temp_segs.emplace_back(x1, y1, x2, y2);
      auto &cur = temp_segs.back();
      ans += cur.Count();
      unordered_set<pair<ll, ll>, pair_hash> st;
      for (int j = 0; j < i; j++) {
        if (cur.IntersectAtIntegerPoint(temp_segs[j], pt)) {
          st.insert(pt);
        }
      }
      for (auto &ele : st) {
        count[ele]++;
      }
    }
    for (auto &pa : count) {
      ans -= pa.second;
    }
    cout << ans << endl;
  }
  vector<Segment> temp_segs;
  int n;
  unordered_map<pair<ll, ll>, int, pair_hash> count;
};
int main() {
  Solver sol;
  sol.solve();
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  if (!b) {
    return a;
  }
  return gcd(b, a % b);
}
struct pair_hash {
  template <typename T, typename U>
  size_t operator()(const pair<T, U> &x) const {
    return hash<T>()(x.first) ^ (1317 + hash<T>()(x.second) << 1);
  }
};
struct Point {
  Point(ll x, ll y) : x(x), y(y) {}
  Point() {}
  ll x;
  ll y;
};
struct Segment {
  Segment(ll x1, ll y1, ll x2, ll y2) {
    if (x1 < x2 || x1 == x2 && y1 < y2) {
      A = Point(x1, y1);
      B = Point(x2, y2);
    } else {
      A = Point(x2, y2);
      B = Point(x1, y1);
    }
    CalculateSlope();
    length = hypot(1.0 * (B.x - A.x), 1.0 * (B.y - A.y));
    a = B.y - A.y;
    b = A.x - B.x;
    c = A.y * B.x - A.x * B.y;
  }

  void CalculateSlope() {
    ll g = gcd(abs(B.x - A.x), abs(B.y - A.y));
    slope.first = (B.x - A.x) / g;
    slope.second = (B.y - A.y) / g;
  }
  bool Parallel(const Segment &another) const { return slope == another.slope; }
  bool Horizontal() const { return A.y == B.y; }
  bool Vertical() const { return A.x == B.x; }
  bool IntersectAtIntegerPoint(const Segment &another, Point &pt) const {
    if (Parallel(another)) {
      return false; // input is guaranteed no same line
    }
    ll den = a * another.b - b * another.a;
    ll num1 = -c * another.b + another.c * b;
    ll num2 = c * another.a - another.c * a;
    if (num2 % den || num1 % den) {
      return false;
    }
    pt.x = num1 / den;
    pt.y = num2 / den;
    if (pt.x >= A.x && pt.x <= B.x)
      return true;
    return false;
  }
  ll Count() const {
    ll g = gcd(abs(B.x - A.x), abs(B.y - A.y));
    return 1LL + min(abs(B.x - A.x), abs(B.y - A.y)) / g;
  }
  pair<ll, ll> slope;
  double length;
  Point A;
  Point B;
  ll a, b, c;
};
class Solver {
public:
  void solve() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    Point pt;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      temp_segs.emplace_back(x1, y1, x2, y2);
      auto &cur = temp_segs.back();
      ans += cur.Count();
      unordered_set<pair<ll, ll>, pair_hash> st;
      for (int j = 0; j < i; j++) {
        if (cur.IntersectAtIntegerPoint(temp_segs[j], pt)) {
          st.emplace(pt.x, pt.y);
        }
      }
      for (auto &ele : st) {
        count[ele]++;
      }
    }
    for (auto &pa : count) {
      ans -= pa.second;
    }
    cout << ans << endl;
  }
  vector<Segment> temp_segs;
  int n;
  unordered_map<pair<ll, ll>, int, pair_hash> count;
};
int main() {
  Solver sol;
  sol.solve();
  return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
  if (!b) {
    return a;
  }
  return gcd(b, a % b);
}
template <typename T, typename U> struct pair_hash {
  size_t operator()(const pair<T, U> &x) const {
    return hash<T>()(x.first) ^ (1317 + hash<T>()(x.second) << 1);
  }
};
struct Point {
  Point(ll x, ll y) : x(x), y(y) {}
  Point() {}
  ll x;
  ll y;
};
struct Segment {
  Segment(ll x1, ll y1, ll x2, ll y2) {
    if (x1 < x2 || x1 == x2 && y1 < y2) {
      A = Point(x1, y1);
      B = Point(x2, y2);
    } else {
      A = Point(x2, y2);
      B = Point(x1, y1);
    }
    CalculateSlope();
    length = hypot(1.0 * (B.x - A.x), 1.0 * (B.y - A.y));
    a = B.y - A.y;
    b = A.x - B.x;
    c = A.y * B.x - A.x * B.y;
  }

  void CalculateSlope() {
    ll g = gcd(abs(B.x - A.x), abs(B.y - A.y));
    slope.first = (B.x - A.x) / g;
    slope.second = (B.y - A.y) / g;
  }
  bool Parallel(const Segment &another) const { return slope == another.slope; }
  bool Horizontal() const { return A.y == B.y; }
  bool Vertical() const { return A.x == B.x; }
  bool IntersectAtIntegerPoint(const Segment &another, Point &pt) const {
    if (Parallel(another)) {
      return false; // input is guaranteed no same line
    }
    ll den = a * another.b - b * another.a;
    ll num1 = -c * another.b + another.c * b;
    ll num2 = c * another.a - another.c * a;
    if (num2 % den || num1 % den) {
      return false;
    }
    pt.x = num1 / den;
    pt.y = num2 / den;
    if (pt.x >= A.x && pt.x <= B.x)
      return true;
    return false;
  }
  ll Count() const {
    ll g = gdc(abs(B.x - A.x), abs(B.y - A.y));
    return 1LL + min(abs(B.x - A.x), abs(B.y - A.y)) / g;
  }
  pair<ll, ll> slope;
  double length;
  Point A;
  Point B;
  ll a, b, c;
};
class Solver {
public:
  void solve() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    Point pt;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
      ll x1, y1, x2, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      temp_segs.emplace_back(x1, y1, x2, y2);
      auto &cur = temp_segs.back();
      ans += cur.Count();
      unordered_set<pair<ll, ll>, pair_hash> st;
      for (int j = 0; j < i; j++) {
        if (cur.IntersectAtIntegerPoint(temp_segs[j], pt)) {
          st.insert(pt);
        }
      }
      for (auto &ele : st) {
        count[ele]++;
      }
    }
    for (auto &pa : count) {
      ans -= pa.second;
    }
    cout << ans << endl;
  }
  vector<Segment> temp_segs;
  int n;
  unordered_map<pair<ll, ll>, int, pair_hash> count;
};
int main() {
  Solver sol;
  sol.solve();
  return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <bits/stdc++.h>

using ULL = unsigned long long;
using namespace std;

struct Segment {
    int ax, ay, bx, by;
}

struct Line {
    int a, b, c;

    Line(const Segment& seg) {
        a = seg.by - seg.ay;
        b = seg.ax - seg.bx;
        c = -a * seg.ax - b * seg.ay;
    }
}

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

long long det(long long a, long long b, long long c, long long d){
    return a * d - b * c;
}

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.c, lin1.b, lin2.c, lin2.b);
    long long dy = det(lin1.a, lin1.c, lin2.a, lin2.c);
    long long d  = det(lin1.a, lin1.b, lin2.a, lin2.b);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, a.ax, a.bx) || !in(y, a.ay, a.by))
        return false;
    if (!in(x, b.ax, b.bx) || !in(y, b.ay, b.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    std::pair<int, int> point;

    for (int i = 1; i < seg.size(); ++i) {
        std::set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, seg[i], seg[j]))) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <bits/stdc++.h>

using ULL = unsigned long long;
using namespace std;

struct Segment {
    int ax, ay, bx, by;
};

struct Line {
    int a, b, c;

    Line(const Segment& seg) {
        a = seg.by - seg.ay;
        b = seg.ax - seg.bx;
        c = -a * seg.ax - b * seg.ay;
    }
};

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

long long det(long long a, long long b, long long c, long long d){
    return a * d - b * c;
}

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.c, lin1.b, lin2.c, lin2.b);
    long long dy = det(lin1.a, lin1.c, lin2.a, lin2.c);
    long long d  = det(lin1.a, lin1.b, lin2.a, lin2.b);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, seg1.ax, seg1.bx) || !in(y, seg1.ay, seg1.by))
        return false;
    if (!in(x, seg2.ax, seg2.bx) || !in(y, seg2.ay, seg2.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    std::pair<int, int> point;

    for (int i = 1; i < seg.size(); ++i) {
        std::set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, seg[i], seg[j]))) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>

using ULL = unsigned long long;

struct Line {
    int a, b, c;

    Line(const Segment& seg) {
        a = seg.by - seg.ay;
        b = seg.ax - seg.bx;
        c = -a * seg.ax - b * seg.ay;
    }
}
struct Segment {
    int ax, ay, bx, by;
}

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

long long det(long long a, long long b, long long c, long long d){
    return a * d - b * c;
}

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.C, lin1.B, lin2.C, lin2.B);
    long long dy = det(lin1.A, lin1.C, lin2.A, lin2.C);
    long long d  = det(lin1.A, lin1.B, lin2.A, lin2.B);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, a.ax, a.bx) || !in(y, a.ay, a.by))
        return false;
    if (!in(x, b.ax, b.bx) || !in(y, b.ay, b.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    pair<int, int> point;

    for (int i = 1; i < seg.size(); ++i) {
        set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, seg[i], seg[j]))) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <bits/stdc++.h>

using ULL = unsigned long long;
using namespace std;

struct Segment {
    int ax, ay, bx, by;
};

struct Line {
    int a, b, c;

    Line(const Segment& seg) {
        a = seg.by - seg.ay;
        b = seg.ax - seg.bx;
        c = -a * seg.ax - b * seg.ay;
    }
};

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

long long det(long long a, long long b, long long c, long long d){
    return a * d - b * c;
}

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.c, lin1.b, lin2.c, lin2.b);
    long long dy = det(lin1.a, lin1.c, lin2.a, lin2.c);
    long long d  = det(lin1.a, lin1.b, lin2.a, lin2.b);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, seg1.ax, seg1.bx) || !in(y, seg1.ay, seg1.by))
        return false;
    if (!in(x, seg2.ax, seg2.bx) || !in(y, seg2.ay, seg2.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    std::pair<int, int> point;

    for (int i = 1; i < segments.size(); ++i) {
        std::set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, seg[i], seg[j]))) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}