codeforce 347c
来源:互联网 发布:地坪找平层算法 编辑:程序博客网 时间:2024/06/03 23:42
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).
Example
Input
2
2 3
Output
Alice
Input
2
5 3
Output
Alice
Input
3
5 6 7
Output
Bob
import java.math.BigDecimal;import java.util.ArrayList;import java.util.HashMap;import java.util.LinkedList;import java.util.Scanner;/** * Created by 95112 on 10/22/2017. */public class ABGame { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int[] input = new int[n]; int max = 0; for (int i = 0 ; i < n ; i++) { input[i] = scanner.nextInt(); if (max < input[i]) max = input[i]; } int v = input[0]; for (int i = 1 ; i < n ; i++) { v = gcd(v,input[i]); } v = max/v - n; if (v%2 == 1) System.out.println("Alice"); else System.out.println("Bob"); } private static int gcd(int a, int b){ if (a < b) { a = b+a; b = a - b; a = a - b; } if (a%b == 0) return b; else return gcd(b,a%b); }}
- codeforce 347c
- Codeforce # C. Average Score
- CodeForce 279C
- codeforce 237 C D
- Codeforce C. Barcode
- Codeforce 57C Array
- Codeforce 240C Practice
- Codeforce 332C
- codeforce 370C
- codeforce 400 C
- codeforce 6C
- codeforce 12C map
- codeforce 14C
- codeforce 18C
- codeforce 447C
- codeforce 20140808 C. Boredom
- codeforce 492 C D
- (288C)codeforce
- swift
- 洛谷P3166 [CQOI2014]数三角形
- 爬虫一些问题
- snacks模拟赛t2
- 周末记录--2017.10.22
- codeforce 347c
- 基于“视频图像”的人脸识别算法
- ACM 大数运算 A/B Problem
- 纯js代码的计时器
- 框架面试题
- 多线程基本概念
- 二分查找总结
- AngularJs路由修改密码表单展示
- 自定义圆形进度条