Good Coins

原创 2018年04月15日 12:15:46

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\n");
                break;
            }
            if(c==1)
            {
                printf("GOOD\n");
                break;
            }
            a=b;
            b=c;
            c=a%b;
        }
    }
    return 0;
}

LeetCode笔记:441. Arranging Coins

n个硬币能摆出多少层的完整楼梯
  • Cloudox_
  • Cloudox_
  • 2016-11-02 10:36:14
  • 1635

【PAT 1068】 Find More Coins 背包问题

1068. Find More Coins (30) 时间限制 150 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard...
  • tiantangrenjian
  • tiantangrenjian
  • 2013-12-15 15:13:25
  • 4188

Gym 100712G Heavy Coins

题目链接:http://codeforces.com/gym/100712/attachments 枚举子集。枚举时判断不满足题目条件:拿掉某几个硬币仍足以支付车费。 附上AC代码...
  • Silenceneo
  • Silenceneo
  • 2016-05-15 21:43:38
  • 358

441. Arranging Coins

441. Arranging Coins You have a total of n coins that you want to form in a staircase shape, w...
  • liuchenjane
  • liuchenjane
  • 2016-10-30 16:46:54
  • 778

HDU 1398 Square Coins (母函数-整数拆分变形)

Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T...
  • IAccepted
  • IAccepted
  • 2014-04-28 17:20:44
  • 2347

Codeforces 876 D. Sorting the Coins 模拟

题意给出n(300000),最初状态表示n个0. 然后给出n个数,表示依次把ai位置置为1. 输出最初和每次变换后的扫描次数. 扫描次数为除了末尾连续的1之外1的个数+1.解法一个变量last记...
  • m0_37809890
  • m0_37809890
  • 2017-10-17 19:39:20
  • 311

[ACM] POJ 2000 Gold Coins

Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20913   Ac...
  • sr19930829
  • sr19930829
  • 2014-07-12 17:13:30
  • 1930

G. Heavy Coins(二进制枚举)

G. Heavy Coins Bahosain has a lot of coins in his pocket. These coins are really heavy, so he always...
  • longshanxiaoxuesheng
  • longshanxiaoxuesheng
  • 2016-04-29 16:09:52
  • 213

【PAT Advanced Level】1068. Find More Coins (30)

最近在学习动态规划,PAT中的这一题就是一个典型的dp问题。 这一题和01背包问题很类似,M相当于背包问题中的背包容量,硬币面值相当于每件物品的重量,背包问题中要求物品价值最大,这里要求物品总重(面值...
  • gzxcyy
  • gzxcyy
  • 2013-11-01 19:53:17
  • 1248

【PAT】1048. Find Coins (25)

题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1048 题目描述: Eva loves to collect coins from al...
  • realxuejin
  • realxuejin
  • 2013-08-26 19:44:58
  • 1448
收藏助手
不良信息举报
您举报文章:Good Coins
举报原因:
原因补充:

(最多只允许输入30个字)