Good Coins Gym - 101020J

It was a beautiful day, the sun was shining, the sky was clear and king Omar was listening to the birds peacefully under his favorite apple tree. Suddenly, an apple fell down and hit his head, and an idea came to him, he decided to reduce the types of coins in his kingdom to two types only. To take a wise choice, he had to choose good coins. We call a group of two coins good if we can exchange any integer amount of money by using them. For example, you can exchange any amount of money by using coins which have the values 3 and 4 so the group {3, 4} is good but you can’t exchange the amount 3 if the two coins have the values 2 and 6, so the group {2, 6} isn’t good. You are about to help king Omar to choose a good group of coins to be the national coins from a set of choices. You program have to test T group of two members where 0<T<5000, and print “GOOD” if the group is good, and “NOT GOOD” if it is not.

Input
The first line of the input contains T the number of test cases, followed by T lines, each line contains tow integers x,y separated by a space and 0 < x,y  ≤  10 ^{} 7

Output
For each line of the input print “GOOD” if {x,y} is good and “NOT GOOD” if it is not.

Examples
Input
4
3 4
2 6
19739 6101
3636 351
Output
GOOD
NOT GOOD
GOOD
NOT GOOD
Note
If someone X wants to give another one Y the amount 4 and the available coins have the values 3 and 5, then X can give Y 8 coins of the value 5 and Y give X 12 coins of the value 3 . 8x5-12x3=4

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int T, a, b, t, c, flag;
    scanf("%d", &T);
    while (T--)
    {
        flag = 0;
        scanf("%d %d", &a, &b);
        if (a<b)
        {
            t = a;
            a = b;
            b = t;
        }
        c = a%b;
        while (c)
        {
            if (c==0)
                flag = 0;
            if (c==1)
                flag = 1;
            a = b;
            b = c;
            c = a%b;
        }
        if (flag)
            printf("GOOD\n");
        else printf("NOT GOOD\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值