CodeForces - 346A gcd
2017-07-20 14:48
197 查看
Description
It is so boring in the summer holiday, isn’t it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn’t contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.
Input
The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2, …, an (1 ≤ ai ≤ 109) — the elements of the set.Output
Print a single line with the winner’s name. If Alice wins print “Alice”, otherwise print “Bob” (without quotes).Sample Input
22 3
3
5 6 7
Sample Output
AliceBob
Hint
Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.题意
A和B玩游戏 给出n个不同的数 A先手 随意找出两个不同的数求他们的差的绝对值并添加到这个集合中 最终谁无法得到新的数字便输
题解:
可以知道两个不同的数求他们的差的绝对值一定是小于最大的数的 可以求下所有数的最大公倍数 那么他们一共能得到的数的个数为 最大数/最大公倍数-n 然后alice赢得条件为上述个数为奇数AC代码
#include <cstdio> typedef long long LL; int gcd(int a,int b){ return !b?a:gcd(b,a%b); } int main(){ int n; scanf("%d",&n); int a; scanf("%d",&a); int mx = a; int temp = a; for (int i = 1; i < n; ++i){ scanf("%d",&a); if (a>mx) mx = a; temp = gcd(temp,a); } int ans = mx/temp-n; if (ans%2) printf("Alice\n"); else printf("Bob\n"); return 0; }
ba61
相关文章推荐
- CodeForces 16C Monitor(gcd,水题)
- Codeforces 475D CGCDSSQ 求序列中连续数字的GCD=K的对数
- Codeforces 338D GCD Table [中国剩余定理]
- Codeforces 798C:Mike and gcd problem
- 【Codeforces Round #196 (Div. 1)】Codeforces 338D GCD Table
- codeforces 75C C. Modified GCD(二分)
- Codeforces 583C/582A 暴力+gcd
- Codeforces 623B:Array GCD
- 【Codeforces 582A】 GCD Table
- Codeforces 583C GCD Table 模拟 map
- Codeforces 583c GCD Table
- Codeforces 894C:Marco and GCD Sequence(构造)
- Codeforces 592C The Big Race 【GCD && LCM】
- codeforces 338D - GCD Table 扩展中国剩余定理
- CSU-ACM2017暑假集训比赛8 - C - GCD Table - CodeForces - 582A
- Codeforces 432 Div. 2-D-Arpa and a list of numbers(枚举倍数求GCD)
- Codeforces 338D GCD Table 中国剩余定理
- Codeforces 338D GCD Table 中国剩余定理
- 【CodeForces】75C - Modified GCD(快速求公约数,upper_bound函数)
- CodeForces 338D GCD Table