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);    }}