【Hrbust】 Alice and Bob (博弈)

本文介绍了一个结合数论与博弈论的游戏“A和B”,详细解析了游戏规则及获胜策略。通过计算特定整数N下可能的状态数,利用记忆数组避免重复计算,最终判断先手玩家Alice是否能赢。

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

A.Alice and Bob
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 150 (37 users)Total Accepted: 31 (29 users)Special Judge: No
Description

Alice and Bob are playing a game called A and B, and the loser will do homework for the winner. The name of the game doesn't come from the initial character of their names. The game is called A and B because they need to write down integer A and integer B in turns and A2 - B2 must be equal to N. N is also an integer given by Jim Zheng. He is the judge of the game. Every time Alice or Bob can write at most 3 sets of A and B, and at least 1 set if there still exist A and B (A2 - B2 = N). The person who cant write A and B in his/her turn will be the loser. In the game, Alice always writes A and B first.

For example, Jim Zheng shows an integer: 5 to Alice and Bob. First, Alice writes 3 sets of A and B: (3, 2), (3, -2), (-3, 2). Then Bob writes 1 set of A and B: (-3, -2). Now, its Alices turn again. But she cant write A and B any more, so she loses.

Now, we can assume Alice and Bob both use the best strategy. Giving you an integer N. Can you tell Alice whether she can win by using the best strategy? Please output yes if Alice can win, or no if she cant.

Input

First line contains an integer T (T >= 1000000), which is the number of cases.

In the next T lines, every line contains an integer N (1 <= N <= 1000000).

Output

Just output one line for each case, output “yes” if Alice can win, or “no” if she can’t.

Sample Input


3
1
2
5


Sample Output

yes
no
no



Author
Zheng Jintao





一个简单的数论和博弈混合的题目。

在算出每个答案后,要用记忆数组保存一下,防止相同数据多次计算。


代码:

#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#define LL long long
#define db double
#define pi acos(-1.0)
#define pr printf
#define sc scanf
#define mod
#define N 1000111
using namespace std;

int c[N];

int main()
{
    int T,i,j,n,a,b,sum;

    for(i=1; i<N; ++i)
        c[i]=-1;

    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);

        sum=0;

        if(c[n]!=-1)
            sum = c[n];
        else
        {
            for(i=1; i*i<=n; ++i)
            {
                if(n%i==0&&((n/i-i)%2==0))
                {
                    if(i==n/i)
                        sum +=2;
                    else
                        sum+=4;
                }
            }
            c[n] = sum;
        }
        puts((sum%4)?"yes":"no");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值