杯具倒水

(机器人协会友情赞助)

在你面前有两个不规则的杯具,分别容积为a升和b升,还有一个水缸(水无限多)可供装水,那么能不能通过两个杯具的装倒水操作,量出c升的水?

输入格式:

输入的第一行包含一个整数n(n<100),表示包括表示测试数据数 接下来n行,每行三个整数a,b,c其中(1<=a

输出格式:

输出n行 每行输出一个整数,1表示可量出c升水,0表示不能

输入样例:

在这里给出一组输入。例如:

3
3 5 4
7 11 5
9 15 10

输出样例:

在这里给出相应的输出。例如:

1
1
0
#include<iostream>
using namespace std;
int gcd(int a,int b) {
	if(b == 0) return a;
	else return gcd(b, a%b);
}
int main() {
	int n;
	cin>>n;
	int a,b,c;
	while(n--) {
		cin>>a>>b>>c;
//		cout<<gcd(a,b)<<endl;
		if(c%gcd(a,b) == 0)
			cout<<"1"<<endl;
		else
			cout<<"0"<<endl;
	}
}
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define PI 3.1415926;

int main()
{
    int t,a,b,c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&a,&b,&c);
       // c=c%(a+b);  可有可无  这道题数据太小了
        if(a<b)  swap(a,b);
        int r;
        while(b)
        {
            r=a%b;
            a=b;
            b=r;
        }//printf("%d\n",a);
        if(c%a==0)  printf("1\n");
        else   printf("0\n");
    }
    return 0;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值