首页 > 学院 > 开发设计 > 正文

hdu5512pagodas(最小公因数)

2019-11-08 19:56:31
字体:
来源:转载
供稿:网友

题目描述:

PRoblem Descriptionn pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labelled from 1 to n. However, only two of them (labelled aand b, where 1≤a≠b≤n) withstood the test of time.Two monks, Yuwgna and Iaka, decide to make glories great again. They take turns to build pagodas and Yuwgna takes first. For each turn, one can rebuild a new pagodas labelled i (i∉{a,b} and 1≤i≤n) if there exist two pagodas standing erect, labelled j and k respectively, such that i=j+k or i=j−k. Each pagoda can not be rebuilt twice.This is a game for them. The monk who can not rebuild a new pagoda will lose the game. InputThe first line contains an integer t (1≤t≤500) which is the number of test cases.For each test case, the first line provides the positive integer n (2≤n≤20000) and two different integers a and b. OutputFor each test case, output the winner (``Yuwgna" or ``Iaka"). Both of them will make the best possible decision each time. Sample Input
162 1 23 1 367 1 2100 1 28 6 89 6 810 6 811 6 812 6 813 6 814 6 815 6 816 6 81314 6 81994 1 131994 7 12 Sample Output
Case #1: IakaCase #2: YuwgnaCase #3: YuwgnaCase #4: IakaCase #5: IakaCase #6: IakaCase #7: YuwgnaCase #8: YuwgnaCase #9: IakaCase #10: IakaCase #11: YuwgnaCase #12: YuwgnaCase #13: IakaCase #14: YuwgnaCase #15: IakaCase #16: Iaka题目理解:代码:
#include <iostream>#include <cmath>using namespace std;int gcd(int a,int b){    if(b==0)    return a;    else    return gcd(b,a%b);}int main(){    int t;    cin>>t;    for(int i=1;i<=t;i++)    {        int n,a,b;        cin>>n>>a>>b;        cout<<"Case #"<<i<<": ";        int tmp=gcd(a,b);        if(tmp==1)        {            if(n%2)            cout<<"Yuwgna"<<endl;            else            cout<<"Iaka"<<endl;        }        else        {            int ans=n/tmp;            if(ans%2)            cout<<"Yuwgna"<<endl;            else            cout<<"Iaka"<<endl;        }    }    return 0;}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表