TOJ 3469.Apples

题目链接:http://acm.tju.edu.cn/toj/showp3469.html


3469.    Apples
Time Limit: 1.0 Seconds    Memory Limit: 65536K
Total Runs: 239    Accepted Runs: 173



There are two piles of apples, one of which contains N apples and another contains M apples. Now we want to put these apples into bags. For some purpose, each of these bags must contains the same number of apples. When we put the first pile of apples into these bags, we get some bags of apples and b1 apples remains, and when we put the second pile of apples into these bags, we get some bags of apples and b2 apples remains. Now the question is: What is the maximum possible number of apples that a bag could contain?

Input

The first line of input is a single integer T, representing the number of test cases. Then T lines follows. Each line gives the number: NMb1b2 in order. All numbers in the input are 32-bit signed integers and 0 ≤ b1 < N; 0 ≤ b2 < MT ≤ 100.

Output

For each test cases, output a sigle line, contain the answer.

Sample Input

2
27 47 0 2
14 17 3 6

Sample Output

9
11



Source: TJU
Submit   List    Runs   Forum   Statistics
最小公倍数,水题


#include <stdio.h>
#define swap(a,b) {a=a+b;b=a-b;a=a-b;}
int gcd(int a,int b){
	if(b==0)
		return a;
	return gcd(b,a%b);
} 
int main()
{
	int n,m,b1,b2,cast;
	scanf("%d",&cast);
	while(cast--){
		scanf("%d%d%d%d",&n,&m,&b1,&b2);
		n-=b1;m-=b2;
		if(n<m)
			swap(n,m);
		printf("%d\n",gcd(n,m));
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值