ACM step 1.2.3 hide handkerchief

Source: Internet
Author: User

The Children's day has passed for some days. Has you remembered something happened at your childhood? I remembered I often played a game called hide handkerchief with my friends.
Now I introduce the game to you. suppose there are n people played the game, who sit on the ground forming a circle, everyone owns a box behind them. also there is a beautiful handkerchief hid in a box which is one of the boxes.
Then Haha (a friend of mine) is called to find the handkerchief. but he has a strange habit. each time he will search the next box which is separated by M-1 boxes from the current box. for example, there are three boxes named A, B, C, and now Haha is at place of. now he decide the m if equal to 2, so he will search a first, then he will search the C box, for C is separated by 2-1 = 1 box B from the current Box. then he will search the Box B, then he will search the box.
So after three times he establishes that he can find the beautiful handkerchief. now I will give you n and M, can you tell me that Haha is able to find the handkerchief or not. if he can, you shoshould tell me "yes", else tell me "poor haha ".

If m and n are not mutually compatible, some students will never be reached.

//

// Main. c

// Hdu1.2.3

//

// Created by Wuxi on 14-10-27.

// Copyright (c) 2014 Wuxi. All rights reserved.

//

 

# Include <stdio. h>

Int gcd (int x, int y)

{

If (X % Y = 0) return y;

Return gcd (Y, X % Y );

}

 

Int main (){

Int m, n, Q;

While (1 ){

Scanf ("% d", & M, & N );

If (M =-1 & n =-1) break;

If (M> = N)

Q = gcd (m, n );

Else q = gcd (n, m );

If (q = 1) printf ("Yes \ n ");

Else printf ("poor Haha \ n ");

}

Return 0;

}

 

ACM step 1.2.3 hide handkerchief

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.