LightOJ 1077 How Many Points? (变种gcd)

题目分析

这道题是挑战程序设计上的原题,就是求gcd(abs(x1-x2), gcd(y1-y2))+1;

#include 
#include 
#include 
#include 
#include 
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;
}

你可能感兴趣的:(ACMlightOJ,数学_数论)