Hdu 5512 Pagodas (reproduction of Shenyang semi-finals)

Source: Internet
Author: User

Hdu 5512 Pagodas (reproduction of Shenyang semi-finals)
PagodasTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission (s): 446 Accepted Submission (s): 331 Problem Description N Pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, labeled from 1 To N . However, only two of them (labeled A And 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 labeled I (I? {A, B} and1 ≤ I ≤ n) If there exist two pagodas standing erect, labeled 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.
Input The 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 .
Output For each test case, output the winner (''yuwgna "or ''iaka"). Both of them will make the best possible demo-each time.
Sample Input

16 2 1 2 3 1 3 67 1 2 100 1 2 8 6 8 9 6 8 10 6 8 11 6 8 12 6 8 6 8 6 6 8 15 6 8 16 6 8 8 1314 6 8 1994 1 13 1994 7 12 

Sample Output
Case #1: Iaka Case #2: Yuwgna Case #3: Yuwgna Case #4: Iaka Case #5: Iaka Case #6: Iaka Case #7: Yuwgna Case #8: yuwgna Case #9: Iaka Case #10: Iaka Case #11: Yuwgna Case #12: Yuwgna Case #13: Iaka Case #14: Yuwgna Case #15: Iaka Case #16: iaka 

Enter a t to indicate that there is a t group of test data. N a B indicates that there are n towers in each row. a and B are the j and k described in the question, (j and k indicate the number of the repaired tower ). Yuwgna first began to repair the tower, and finally lost. Note that each tower that can be constructed must meet the requirements of I = j + k or I = j-k.
Solution: 1. First, determine whether there is 1 in a and B. If so, any tower can be constructed. 2. If there is no 1 in a and B, judge whether a and B are mutually qualitative. If there is mutual quality, there will certainly be 1, so that every tower can be constructed. 3. If there is no mutual quality, only n/gcd (a, B) can be used to build the tower ); finally, you can determine whether the number of towers that can be built is an odd or even number. For details, see the code.
#include 
 
  #include 
  
   #include 
   
    using namespace std;int gcd(int a,int b){    if (a%b==0)        return b;    return gcd(b,a%b);}int main(){    int t;    int c=1;    scanf("%d",&t);    while (t--)    {        int flag=0;        int n,a,b;        scanf("%d%d%d",&n,&a,&b);        if (a==1||b==1)        {            if (n%2==1)                flag=1;        }        else        {            if (gcd(a,b)==1)            {                if (n%2==1)                    flag=1;            }            else            {                int k=n/gcd(a,b);                if (k%2==1)                    flag=1;            }        }        printf ("Case #%d: ",c++);        if (flag==1)            printf ("Yuwgna\n");        else            printf ("Iaka\n");    }    return 0;}
   
  
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.