Gym 100952G&&2015 HIAST Collegiate Programming Contest G. The jar of divisors【简单博弈】

G. The jar of divisors

time limit per test:2 seconds
memory limit per test:64 megabytes
input:standard input
output:standard output

Alice and Bob play the following game. They choose a number N to play with. The rules are as follows:

- They write each number from 1 to N on a paper and put all these papers in a jar.

- Alice plays first, and the two players alternate.

- In his/her turn, a player can select any available number M and remove its divisors including M.

- The person who cannot make a move in his/her turn wins the game.

Assuming both players play optimally, you are asked the following question: who wins the game?

Input

The first line contains the number of test cases T (1  ≤  T  ≤  20). Each of the next T lines contains an integer (1  ≤  N  ≤  1,000,000,000).

Output

Output T lines, one for each test case, containing Alice if Alice wins the game, or Bob otherwise.

Examples
Input
2
5
1
Output
Alice
Bob

题目链接:http://codeforces.com/gym/100952/problem/G

题意:有一个容器里装着1-n n个数,A和B每次任意说一个数m,那么他要拿走容器里m的所有因子,如果谁拿空了容器,那么他输了,求先手赢还是后手赢

思路:只有1是后手赢,因为1只能拿一次,大于1的情况,假设a和b都不是聪明的,假设先手出x,后手出y,结果是后手赢,那么现在a和b都是聪明的,先手可以直接出x*y(即先手可以复制后手的操作,先手的操作可以包括后手的操作),则可以赢后手,所以大于1的情况一定是先手赢!

下面给出AC代码:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 inline int read()
 4 {
 5     int x=0,f=1;
 6     char ch=getchar();
 7     while(ch<'0'||ch>'9')
 8     {
 9         if(ch=='-')
10             f=-1;
11         ch=getchar();
12     }
13     while(ch>='0'&&ch<='9')
14     {
15         x=x*10+ch-'0';
16         ch=getchar();
17     }
18     return x*f;
19 }
20 inline void write(int x)
21 {
22     if(x<0)
23     {
24         putchar('-');
25         x=-x;
26     }
27     if(x>9)
28         write(x/10);
29     putchar(x%10+'0');
30 }
31 int main()
32 {
33     int T;
34     T=read();
35     while(T--)
36     {
37         int n;
38         n=read();
39         if(n>1)
40             printf("Alice\n");
41         else printf("Bob\n");
42     }
43     return 0;
44 }

 

posted @ 2017-07-25 10:42  Angel_Kitty  阅读(443)  评论(0编辑  收藏  举报