Gym 100952 G. The jar of divisors

本文解析了一道关于博弈论的游戏题,题目描述了Alice和Bob通过移除数及其因数的方式进行游戏,最终确定胜者。文章给出了简洁的代码实现,并得出结论:当输入数n模6等于1时,Bob获胜;否则,Alice获胜。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
这道题我自己都有点迷茫,是个博弈题,结论就是n%6==1?"Bob":"Alice"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int main()
{
    ll t,n;
    scanf("%lld",&t);
    while(t--)
    {
        cin>>n;
        if(n%6==1) puts("Bob");
        else puts("Alice");
    }
    return 0;
}

 



转载于:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7199270.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值