Yet Another Number Game

In our question said that “both play optimally”. and in the question said that “a player can subtract from N any proper divisor (not equal to N)”.
I use this method:
n=49
d(49)={1,7,49}
1)Alice: n=49-1=48

d(48)={1,2,3,4,6,8,16,24,48}
2)Bob:n=48-24=24

d(24)={1,2,3,4,6,12,24}
3)Alice: n=24-12=12

d(12)={1,2,3,4,6,12}
4)Bob: n=12-6=6

d(6)={1,2,3,6}
5)Alice: n=6-3=3

d(3)={1,3}
6)Bob: n=3-1=2

d(2)={1,2}
7)Alice: n=2-1=1
and Alice win.

but there is another way:

n=49
d(49)={1,7,49}
1)Alice: n=49-7=42

d(42)={1,2,3,6,7,14,21,42}
2)Bob:n=42-21=21

d(21)={1,3,7,21}
3)Alice: n=21-7=14

d(14)={1,2,7,14}
4)Bob: n=14-7=7

d(7)={1,7}
5)Alice: n=7-1=6

d(6)={1,2,3,6}
6)Bob: n=6-3=3

d(3)={1,3}
7)Alice: n=3-1=2

d(2)={1,2}
8)Bob: n=2-1=1
and Bob win.

which is optimally?first or second ? and can you says that which test my program give wrong answer?

Sometimes no-one have time 0:-)

For test

``````1
4
``````

your code returns BOB, but ALICE is the winner if she substracts 1 in her first move…

Optimally simply means that if there is possibility the player win, he/she will make move to win and not the losing move…

In my example above, there are two possibilities: Alice substract 1 or 2, but she wins if she substracts 1, so logically she will not substract 2…

#include
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t,n,x;
cin>>t;
while(t–)
{
cin>>n;
if(n%2==0)
cout<<“ALICE\n”;
else
cout<<“BOB\n”;
}
return 0;
}

Word Optimally is not clear. One can subtract any divisor.

I case of 4. If Alice subtracts 1 first. She wins.
If she subtracts 2 First, she looses.

Can you give the code that you have submitted? Else it will be difficult to say what’s wrong…

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

``````int main()
{
int t,n;

scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int count=0;
while(n!=1)
{
count++;
if(n%2==0) n/=2;
else if(n%3==0 && n>3) n-=n/3;
else if(n%5==0 && n>5) n-=n/5;
else n--;
}
printf("%s\n",(count%2==0 ? "BOB":"ALICE"));
}
system("pause");
return 0;
}``````

why do anyone answer my question?