A.Alice and Bob | |||||
| |||||
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 can’t 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, it’s Alice’s turn again. But she can’t 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 can’t. | |||||
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;
}