几何,求两整数点确定的线段上的整数点的个数
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int gcd(int a,int b) { return a%b==0?b:gcd(b,a%b); } int main() { int x1,x2,y1,y2; while(cin>>x1>>y1>>x2>>y2) { int x=abs(x1-x2); int y=abs(y1-y2); int t=gcd(x,y); //cout<<t<<endl; cout<<y/(y/t)+1<<endl; } return 0; }