zoukankan      html  css  js  c++  java
  • Good Coins

    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

    Copy

    4
    3 4
    2 6
    19739 6101
    3636 351
    

    output

    Copy

    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

    题意:不断求余,要是余数是0 NOT  GOOG  是1 GOOG

    #include <stdio.h>
    int main()
    {
        int t,a,b,i,c,p;
        scanf("%d",&t);
        while(t--)
        {
             c=2;
            scanf("%d%d",&a,&b);
            if(a<b)
            {
                p=a;a=b;b=p;
            }
            c=a%b;
            while(1)
            {
                if(c==0)
                {
                    printf("NOT GOOG
    ");
                    break;
                }
                if(c==1)
                {
                    printf("GOOD
    ");
                    break;
                }
                a=b;
                b=c;
                c=a%b;
            }
        }
        return 0;
    }
  • 相关阅读:
    [BetterExplained]书写是为了更好的思考
    java 连接 mysql 数据库 ..password [yes]问题
    学习密度与专注力
    抠鼻屎的方法
    张飞流水账(摘)
    用 C 语言 连接 mysql (问题已解决)
    编程的首要原则(s)是什么?
    Tomat源码学习(二)(转载)
    [BetterExplained]为什么你应该(从现在开始就)写博客
    事件 代理 练习
  • 原文地址:https://www.cnblogs.com/zcy19990813/p/9702822.html
Copyright © 2011-2022 走看看