Take stone game (gcd)

 

Jun garlic and broccoli sister playing a game, they ground the n pieces of stones in a row, numbered from 1 to n. Initially, the random extraction of garlic Jun 2 stones thrown away, assuming two stones garlic Jun withdrawn numbered a, b. Rules of the game are as follows, garlic and broccoli Jun sister two take turns to take the child, each taking the child, assuming that someone removed stones numbered i, you must find a pair j, k satisfies i = j- k or i = j + k, and the number j, k of the stone has been removed, and if not who should take stones, and is considered lost. Jun garlic compare gentleman, let broccoli sister upper hand.

Input Format

The first line Enter an integer t (1 <t≤500), represents Jun garlic and broccoli sister were t innings game.

For each game, the input three integers n (2 <n <20000), a, b (1 <a, b <n), to ensure a, b are not equal.

Output Format

If garlic Jun won the game, his output suantou, if broccoli sister won, input line huaye.

Sample input

5
8 6 8
9 6 8
10 6 8
11 6 8
12 6 8

Sample Output

suantou 
suantou 
Huaye 
Huaye 
suantou

 

Think of the process of the Euclidean seeking gcd, can be taken out of the last stone must be a multiple of the number of gcd (a, b) number.

 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <stack>
 9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <sstream>
13 #include <ctime>
14 const int INF=0x3f3f3f3f;
15 typedef long long LL;
16 const int mod=1e9+7;
17 const int maxn=1e5+10;
18 using namespace std;
19 
20 int gcd(int a,int b)
21 {
22     return b?gcd(b,a%b):a;
23 }
24 
25 int main()
26 {
27     #ifdef DEBUG
28     freopen("sample.txt","r",stdin);
29     #endif
30     
31     int T;
32     scanf("%d",&T);
33     while(T--)
34     {
35         int n;
36         scanf("%d",&n);
37         int a,b;
38         scanf("%d %d",&a,&b);
39         if((n/gcd(a,b))&1) printf("huaye\n");
40         else printf("suantou\n");
41     } 
42     
43     return 0;
44 }

 

 

 

-

Guess you like

Origin www.cnblogs.com/jiamian/p/12222581.html