题目分析
这道题是挑战程序设计上的原题,就是求gcd(abs(x1-x2), gcd(y1-y2))+1;
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b){
return !b?a:gcd(b, a%b);
}
int main(){
int T;
scanf("%d", &T);
for(int kase = 1; kase <= T; kase++){
LL x1, y1, x2, y2;
scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
printf("Case %d: %lld\n", kase, gcd(abs(x1-x2), abs(y1-y2))+1);
}
return 0;
}