CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(easy) » Yet Another Number Game

Yet Another Number Game

Problem code: NUMGAME

  • Submit
  • All Submissions

All submissions for this problem are available.

Alice and Bob play the following game. They choose a number N to play with. The rules are as follows :

1) Alice plays first, and the two players alternate.

2) In his/her turn, a player can subtract from N any proper divisor (not equal to N) of N. The number thus obtained is the new N.

3) The person who cannot make a move in his/her turn loses the game.

Assuming both play optimally, who wins the game ?

Input :

The first line contains the number of test cases T. Each of the next T lines contains an integer N.

Output :

Output T lines, one for each test case, containing "ALICE" if Alice wins the game, or "BOB" otherwise.

Sample Input :
2
1
2

Sample Output :
BOB
ALICE

Constraints :
1 <= T <= 10000
1 <= N <= 1000000000

Note : For the first test case, Alice cannot make any move and hence Bob wins the game. For the second test case, Alice subtracts 1 from N. Now, Bob cannot make a move and loses the game.


Author: syco
Date Added: 11-04-2010
Time Limit: 1 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

hey m using a turbo c++ 4.5

rohan_bania @ 4 Jul 2010 10:23 PM

hey m using a turbo c++ 4.5 compiler...

i submitted d solution but its givin an error...

i can execute d prog on my pc...

can u help me out here....

http://www.codechef.com/wiki/

indraneel @ 4 Jul 2010 11:12 PM

http://www.codechef.com/wiki/faq

k thaks got it..

rohan_bania @ 5 Jul 2010 02:13 PM

k thaks got it..

Does timelimit error mean my

vardhan2k8 @ 8 Aug 2010 03:47 AM

Does timelimit error mean my solution has errors? or is it just took long time to provide all the right answers to the test cases?

Is it possible to provide additional test cases to validate my result?

See the FAQ.

triplem @ 8 Aug 2010 04:37 AM

See the FAQ.

what is the meaning of "play

apix @ 19 Sep 2010 02:38 AM

what is the meaning of "play optimally"?

It means each player will

triplem @ 19 Sep 2010 04:23 AM

It means each player will make the best possible moves, knowing their opponents will make the best possible moves too.

k got it "optimally".

nirajkant @ 23 Sep 2010 07:09 PM
k got it "optimally".

MY submission time is 0.00 i

nirajkant @ 23 Sep 2010 07:10 PM
MY submission time is 0.00 i m not in the list.

got it.... damn good way to

nikku @ 22 Oct 2010 06:03 PM

got it....

damn good way to present the problem......

here only when input is 1

pandyajay1 @ 26 Oct 2010 04:52 PM

here only when input is 1 ....alice will win else bob will win(always).....i did yhe same thing....why am i getting the wrong answer error?

please help me...........

sorry on input==2....alice

pandyajay1 @ 26 Oct 2010 04:54 PM

sorry on input==2....alice will win else bob will win.....my mistake in my last comment.........help me.......

If the input is 6, Alice can

triplem @ 27 Oct 2010 10:15 AM

If the input is 6, Alice can win by subtracting 3. Bob will be forced to subtract 1, and Alice will subtract 1 again to win.

Please verify if this is

neverserious @ 6 Dec 2010 11:21 PM

Please verify if this is really a level 2 problem or not...because the solution is pretty straight forward and can be proved using induction.

Here is a question for test

binbashx @ 25 Dec 2010 02:51 PM

Here is a question for test case N=1. The problem description clearly states that  "In his/her turn, a player can subtract from N any proper divisor (not equal to N) of N. The number thus obtained is the new N". So when N = 1 how can Alice subtract 1 from 1 (1 equal to N)?....as well for N=2 test case if Alice starts then 2-1 = 1  left for Bob to subtract from which he cannot make a move since 1 equals the new N?.....Please clarify me if Iam wrong. Thanks

Alice never subtracts 1 from

triplem @ 25 Dec 2010 03:13 PM

Alice never subtracts 1 from 1. The first test case is N=1; Alice cannot move therefore Bob wins. The second test case is N=2; Alice subtracts 1 and now Bob cannot move, so Alice wins.

My bad dude...I mistook the

binbashx @ 25 Dec 2010 05:43 PM

My bad dude...I mistook the first input 2 to be N....where it is just the no of inputs....sorry about that..Thanks.

To admin: First I was getting

rajneesh2k10 @ 30 Dec 2010 05:47 PM

To admin:

First I was getting TLE error. Then I looked back into the algorithm and wrote something different. Now I am stuck with Runtim Error. Don't know where is the problem. Please help.

http://www.codechef.com/viewsolution/409212

500000005 chars is far too

triplem @ 31 Dec 2010 02:41 AM

500000005 chars is far too much memory to store on the stack (ie inside a function); but even if you moved it onto the heap (global) it is still too much memory.

@Stephen: Agreed! I think

rajneesh2k10 @ 31 Dec 2010 08:08 AM

@Stephen: Agreed! I think this solution should work good but why TLE? http://www.codechef.com/viewsolution/409182

Time complexity is of the order O(n^2). Is there any other algorithm with improved complexity?

Have you tried testing your

triplem @ 31 Dec 2010 09:42 AM

Have you tried testing your code at all? It runs forever on nearly every single input. Even if it were O(N^2), your program should be able to solve a total of 10000 test cases of size 1000000000 - you wouldn't be able to solve 1 test case of size 100000 in one second with O(N^2), let alone that.

@Stephen: Damn!! I again

rajneesh2k10 @ 31 Dec 2010 11:51 AM

@Stephen: Damn!! I again din't read the problem statement carefully! :( :(. Sorry! Whole Code was wrong!

I learnt one thing here- I used to think, time limit is for every individual test case, but as u say its for the entire test suit. Thanks! :)

On my machine, my program

shivkhare @ 5 Jan 2011 06:46 AM

On my machine, my program shows me total time consumed as 20 ms for 10000 inputs  with each input being  a random number between 1 to 1000000000... After submission, the time is .54 sec.. this is a huge difference? The language is C#..

plz look at my code.

gn13 @ 17 Jan 2011 09:54 AM

plz look at my code.

awesome game theory problem

sutanug @ 18 Feb 2011 09:54 PM

awesome game theory problem :


an odd # is divisible by odd only so a person getting odd number gives opponent even who in turn if gives opponent again odd(by substracting 1 which he always can as he gets even); ultimately the 1 st person always gets odd and reaches 1 at last and loses implying...


person getting odd loses so if Alice gets odd ; Bob should always try to keep him odd by taking 1 otherwise his opponent can take 1 or win himself...............here comes the meaning of optimal.

@Stephen=i am getting time

pranavrocks @ 19 Feb 2011 07:42 PM

@Stephen=i am getting time limit extended again and again ...plz help me

http://www.codechef.com/viewsolution/461254

here my code ...tell me the prob ...

i am stuck with run time

pavan73 @ 28 Feb 2011 05:06 PM

i am stuck with run time error..please tell me where is the problem.....

My code is giving correct

sachin_nagar @ 3 Mar 2011 01:48 AM

My code is giving correct output,but at the time of submission it shows Wrong Answer.

Please Admin help me to out of my problen..

http://www.codechef.com/submit/complete/49083-6308--4d6ea54e9b5ac

veryyyyyyyyyyyyy easy...

vishal_dhiman @ 11 Mar 2011 02:23 AM

veryyyyyyyyyyyyy easy... loved ths one.. took only 5 minutes of deep thinking.

waw...what an problem.... i

cooltodinesh @ 12 Mar 2011 11:10 AM

waw...what an problem....

i coded this very complex and observed on test cases and hahaha it's so simple.

im observing it too, and get

hansfryko @ 13 Mar 2011 10:07 PM

im observing it too, and get the answer, but i still dont really know, why? :)

My program is just working

alternator @ 20 Mar 2011 08:11 PM

My program is just working fine in TURBOC, but i m getting TLE here, can any 1 help me.....

Following is the mine soln:

#include<stdio.h>
int main()
{
int i,t,n,flag;
scanf("%d",&t);
while(t--)
{
flag=0;
scanf("%d",&n);
for(i=n/2;i>=1;)
{
if(n%i==0)
{
n-=i;
i=n/2;
flag=!flag;
}
else
i--;
}
if(flag)
printf("ALICEn");
else
printf("BOBn");
}
return 0;
}

#include<stdio.h>int

reetika @ 26 Mar 2011 10:35 AM

#include<stdio.h>
int main(){
int t,n,j,i,flag=0;
scanf("%d", &t);
if((t>=1) && (t<=10000))
{
  for(i=0; i<t; i++)
  {
    scanf("%d", &n);
    if((n<=1000000000) && (n>=1)){
    for(j=n/2;n!=1;)
    {
     if(n%j==0)
     {
      n=n-j;flag=!flag;j=n/2;
     }
     else
      j--;
    }
    if(flag)
    {
      printf("Alicen");
    }
    if(!flag)
    {
      printf("Bobn");
    }flag=0;
  }
  }
}
return 0;
}

my program execute and work

yashashya @ 14 Apr 2011 12:09 PM

my program execute and work fine in my comp. but gives wrong answer there why it is happend.......?

How do you know it works fine

mkagenius @ 14 Apr 2011 05:05 PM

How do you know it works fine on your computer.?

problem in this line   if(n%2

mkagenius @ 14 Apr 2011 05:28 PM

problem in this line   if(n%2 == 0)   .

Hi Admin, I have submitted

fanendra22 @ 25 Apr 2011 12:48 AM

Hi Admin,

I have submitted the solution with ID 532563. I have checked for some test cases and my code is working fine. But is showing WA in your system. Can you tell me for which test case it is failing or what is the reason it is showing wrong answer

Hi, Can someone take a look

puzzlebot @ 3 May 2011 12:35 PM

Hi,

Can someone take a look at my code and see which part could be optmized ... I am getting a TLE message.

Thanks

Link to my

puzzlebot @ 3 May 2011 12:35 PM

Link to my code:

http://www.codechef.com/viewsolution/537982

@Aparna Nobody can see your

vikram535 @ 3 May 2011 02:17 PM

@Aparna Nobody can see your link...the solutions to this problem are not public

@vikram - anyone who has

triplem @ 3 May 2011 03:18 PM

@vikram - anyone who has solved the problem can see code.

@Aparna - other than the fact that your algorithm is wrong (for example, you assume each player will always subtract the biggest possible factor, which certainly isn't the best strategy), N can be up to 1000000000 - that's a pretty huge number. If N were a prime just under that, you'd have to loop from 1 up to 31000 or so just to find a single move, let alone the entire game or 10000 test cases of that size.

I'm afraid you'll need to start from scratch - make sure your algorithm will run in time before you write any code at all.

hey... i maked the game

vinay2707 @ 3 May 2011 10:08 PM

hey...

i maked the game programme... but i do not understand that how can take the timer in turbo C++....???

can any one help me...??

Hi stiphen , why my code is

sapta9433 @ 6 May 2011 07:32 AM

Hi stiphen , why my code is giving runtime error ? Is it out of memory issue ? Please let me know ...

  • /*
  • * Yet Another Number Game
  • */
  • import java.io.BufferedReader;
  • import java.io.InputStreamReader;
  • /**
  • * @author Saptarshi Chatterjee (sapta9433)
  • * @version 1.0
  • * @date May 3,2011.
  • */
  • public class Main {
  • public static void main(String[] args) throws Exception {
  • BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  • int t = Integer.parseInt(br.readLine()),maxDiv=1,i;
  • long n;
  • final StringBuffer ALICE =new StringBuffer("ALICE");
  • final StringBuffer BOB =new StringBuffer("BOB");
  • for (; t > 0; t--) {
  • n = Integer.parseInt(br.readLine());
  • //if n is not divisible by 2 we can increment i by 2 to reduce looping.
  • for(i=2;i*i<=n;i+=2) {
  • if(n%i==0){
  • maxDiv =i;
  • break;
  • }
  • }
  • maxDiv = (int)n / maxDiv;
  • if (maxDiv == n){
  • maxDiv = 1;
  • }
  • // always give oppnt max pick + min pick (here 1) + 1
  • if((n-1)%(maxDiv + 1) == 0){
  • System.out.println(BOB);
  • }else{
  • System.out.println(ALICE);
  • }
  • }
  • }
  •  
  • }
  • @Admin, can you please see my

    soumyaukil @ 18 May 2011 06:26 PM
    @Admin, can you please see my code : I am getting TLE. http://www.codechef.com/viewsolution/550234

    simply check if n is odd or

    aayush123 @ 2 Jun 2011 03:03 AM
    simply check if n is odd or even...... enjy..:)))

    i use dev c++ 4.9.9.2 and my

    prakhar3agrwal @ 4 Jun 2011 02:42 PM
    i use dev c++ 4.9.9.2 and my programs run successfully there,but on the compiler i have selected in codechef gives me wrong answerand time limit exceeds.. please provide a solution.......thank you...

    I am getting Runtime Error. I

    gnuger @ 5 Jun 2011 10:06 PM
    I am getting Runtime Error. I am following syntax (during runtime) program inputfile outfile

    @gnuger :: You dont need to

    mkagenius @ 5 Jun 2011 10:24 PM
    @gnuger :: You dont need to read from file. Just read using scanf and print using printf.

    aint this prob just abt odd

    ravinder_singh @ 15 Jun 2011 12:51 PM
    aint this prob just abt odd or even input??

    a very nice problem....hats

    flexicoder @ 18 Jun 2011 09:40 AM
    a very nice problem....hats off to the person who thought of it.... although I have one very important query regarding the way execution time is calculated here. I'm sure my couldn't be optimized more but i still got 0.01s execution time.....and when I copy pasted someone's code with 0.00s execution time(sorry abt that bt I had to check!) I got 0.02s time....then how are they getting 0.00s execution time??? I know it doesn't matter much here but it may in tougher problems and I'd like my code to be the most efficient. Therefore @admins I request you to please clarify this.....

    a very nice problem....hats

    flexicoder @ 18 Jun 2011 09:40 AM
    a very nice problem....hats off to the person who thought of it.... although I have one very important query regarding the way execution time is calculated here. I'm sure my couldn't be optimized more but i still got 0.01s execution time.....and when I copy pasted someone's code with 0.00s execution time(sorry abt that bt I had to check!) I got 0.02s time....then how are they getting 0.00s execution time??? I know it doesn't matter much here but it may in tougher problems and I'd like my code to be the most efficient. Therefore @admins I request you to please clarify this.....

    m getting Time Exceeded

    rijul007 @ 19 Jun 2011 01:28 PM
    m getting Time Exceeded Error... please could anyone tell me how i could optimize my code........... import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.IOException; class NumGame { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out,true); int t = Integer.parseInt(br.readLine()); int N; int m=0; for(int i=0;i0) { if(N%j==0) { N=N-j; j=N; m=m+1; } j--; } if(m%2==1) pw.println("Alice"); else pw.println("Bob"); } pw.close(); } }

    Wow! But can sm1 explain why

    malaykeshav @ 22 Jun 2011 01:46 AM
    Wow! But can sm1 explain why this is happening????

    I was able to finish it but I

    rajatkhanduja @ 22 Jun 2011 11:36 AM
    I was able to finish it but I am still not sure why it worked. I checked with a lot of test cases to reach the conclusion that just odd/even test is enough. But I couldn't prove it. If f(x) gives the output when 'x' is the input, then this is all I could conclude :- if f(n) = "BOB" then f(n+1) = "ALICE" (Since Alice could just take out '1' and then the problem is same as "BOB" having n left .. which we know would be won by the 'opposite' player i.e. Alice. ) Also, if f(n)="ALICE" then f(n+1) = "BOB" when n+1 is prime ... I couldn't prove for all other cases.

    @admin i struggle in many

    whitebyte @ 19 Jul 2011 11:43 PM
    @admin i struggle in many prblms only because of lack of test cases provided

    @admin ....i checkd lots of

    anu120987 @ 13 Sep 2011 03:23 AM
    @admin ....i checkd lots of test cases and then prove for them using previous results...but can u provide d exact mathematical prove for it...thanx in advance

    this is simple problem.. in

    vishalb1204 @ 2 Oct 2011 12:00 PM
    this is simple problem.. in any number except 1 , alice has to win since substract (n-1) from n which give 1 . bob cannot substract since 1 == 1 . so alice has to win. :) am i right?

    @vishalb1204: ALICE or BOB

    vi3k6i5 @ 5 Oct 2011 11:30 AM
    @vishalb1204: ALICE or BOB can only subtract from N a number that is a perfect divisor of N other then N itself. so if N=7 they may not subtract (7-1)=6 from it. they will have to subtract 1 from it. and then the game will continue for 6 as N.

    @malaykeshav : H(n) : "Vk in

    cyberax @ 9 Oct 2011 08:34 PM
    @malaykeshav : H(n) : "Vk in [|1;n|] : k is even => next player wins, k is odd => next player looses." demonstration by mathematical induction.

    Consider a number N = 8 1st

    chaitu2289 @ 20 Oct 2011 12:44 PM
    Consider a number N = 8 1st method: Alice --> 8-2 = 6 Bob --> 6-3 = 3 Alice --> 3-1 = 2 Bob --> 2-1 =1 ------------> Bob is winner 2nd method Alice --> 8-4 = 4 Bob --> 4-2 = 2 Alice --> 2-1 = 1 ------------> Alice is winner Winner depends on the number the player has subtracted. How can there be unique solution for every 'n'. If we are given number 8, what is the output we have to print?

    import

    vaddebalu @ 2 Nov 2011 07:04 PM
    import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Random; public class Main{ final StringBuffer bob=new StringBuffer("BOB"); final StringBuffer alice=new StringBuffer("ALICE"); final StringBuffer sb3=new StringBuffer("play ur number"); private int validinput(int pnum) throws IOException{ System.out.println(sb3); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int a1=Integer.parseInt(br.readLine()); if(a1>=pnum){ System.out.println("not a valid number "+a1+" ,should be less than generated number"); a1=validinput(pnum); } return a1; } private void alicePlays(int pnum)throws IOException{ if(pnum==1){ System.out.println(bob); } if(pnum>1){ int a1=validinput(pnum); pnum=pnum-a1; bobPlays(pnum); } } private void bobPlays(int pnum)throws IOException{ if(pnum==1){ System.out.println(alice); } if(pnum>1){ int a1=validinput(pnum); pnum=pnum-a1; alicePlays(pnum); } } public void play(int pnum)throws IOException{ int lnum=pnum; alicePlays(lnum); } public static void main(String[] as) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int a=Integer.parseInt(br.readLine()); Main m=new Main(); int numbersList[]=new int[a]; for(int i=0;i

    http://www.codechef.com/views

    vaddebalu @ 2 Nov 2011 07:38 PM
    http://www.codechef.com/viewsolution/720839 shall anyone tell why above code is not working?

    can i use function calls

    kp25 @ 30 Nov 2011 01:48 PM
    can i use function calls within the program(user defined)... or no function calls should be used.?

    can anyone give me some more

    chaubey12 @ 9 Dec 2011 02:28 PM
    can anyone give me some more example

    my code #include #include

    pankaj_saini @ 13 Dec 2011 02:11 PM
    my code #include #include #include int main() { int t,n,i,count,flag; scanf("%d",&t); while(t--) { count = 0; scanf("%d",&n); while(n>1) { flag = 0; if(n%2==0) { count++; n=n-n/2; flag = 1; continue; } if(n%3==0) { count++; n=n-n/3; flag = 1; continue; } for(i=5;i<=sqrt(n);i++) { if(n%i==0) { count++; n=n-n/i; flag = 1; break; } if(n%(i+2)==0) { count++; n=n-n/(i+2); flag = 1; break; } i = i + 6; } if(flag == 0) { n = n-1; count++; } } if(count%2==1) printf("ALICE"); else printf("BOB"); } return 0; } is getting time exceeded error, help me out to remove it

    The most easiest problem on

    DevilsEye @ 24 Dec 2011 03:27 PM
    The most easiest problem on Codechef i must say.. & they way the problem is expressed marvelous

    @ admin, I am having TLE

    aviator31 @ 25 Dec 2011 11:15 PM
    @ admin, I am having TLE problem. Could u suggest me some ways to get over this

    The logic behind this is that

    r00k1e2k11 @ 28 Jan 2012 11:40 PM
    The logic behind this is that the only factors of an odd number are also odd, and odd - odd = even ... Rest of the things can be figured out easily..:)

    somebody please tell me who

    prabhakaran @ 1 Mar 2012 03:17 PM
    somebody please tell me who is the winner for N=4?

    coolest problem

    prkshverma09 @ 5 Mar 2012 11:04 PM
    coolest problem

    For N=4, Bob is the winner.

    s1s5 @ 17 Mar 2012 03:10 AM
    For N=4, Bob is the winner.

    In case of N=4, Shouldn't

    imithya @ 28 Mar 2012 09:28 AM
    In case of N=4, Shouldn't Alice be the winner? Divisors = 1 or 2 If she plays 1, N=3 in which case she would win however, if she plays 2, N=2 in which case she would lose. So she would obviously play 1 as both Alice and Bob are playing optimally, so Alice should win this game.

    really awsum problem....

    amarekano @ 30 Mar 2012 06:50 PM
    really awsum problem.... Respect to the guy/gal who created it. Cheers pal!!! :)

    @Admin My problem solution is

    cooolshekhar @ 8 Apr 2012 10:40 PM
    @Admin My problem solution is accepted while it giving me BOB for N=4 while it should be Alice because alice take 1 divisor out from 4 and finally 4-1=3 for bob which is odd then bob would loose

    Hi All, I am able to solve

    sandeep_prusty @ 22 Apr 2012 05:45 PM
    Hi All, I am able to solve this as it is just even odd. Even I can prove using induction. Is there any way to prove this other then inductive method. ?

    @imithya: You are correct,

    abhishek_t @ 27 Apr 2012 07:37 PM
    @imithya: You are correct, Alice is the winner for N=4.

    #include int main() { long

    rajrockzz07 @ 15 May 2012 09:29 PM
    #include int main() { long int i,t,n,flag; scanf("%ld",&t); while(t--) { flag=0; scanf("%ld",&n); while( i=n/2 && n%i==0) { n-=i; i=n/2; flag=!flag; } i--; if(flag) printf("ALICEn"); else printf("BOBn"); } return 0; } thats the correct code.....

    huh guys this is very simple

    fayaz786 @ 18 May 2012 02:05 PM
    huh guys this is very simple program........see optimal play involves choosing 1 as the divisor in each case hence you need to substract 1 from N everytime thats it

    @admin For n=7 7A6B3A2B1

    super_geek @ 19 May 2012 01:26 PM
    @admin For n=7 7A6B3A2B1 ALICE LOSES 7A6B4A3B2A1 BOB LOSES Am I missing something.

    @super_geek: Your assessment

    jigsaw004 @ 19 May 2012 06:24 PM
    @super_geek: Your assessment in wrong in the respect that, in your second scenario i.e.: 7A6B4A3B2A1, Bob didn't play optimally. He should have subtracted 3 from 6 rather than 2.The problem statement clearly asserts that both player play optimally. P.S. This is not strictly a 'game'. Hope this helps!

    awesumest problem evr...

    mjnovice @ 1 Jun 2012 02:11 AM
    awesumest problem evr...

    please throw some more light

    dare1_09 @ 2 Jun 2012 11:29 PM
    please throw some more light on the optimally thing!!

    No, matter how the game is

    stonu @ 18 Jun 2012 06:22 PM
    No, matter how the game is played, whether optimally or not, if the number is even Alice wins, and if its odd, Bob wins. It entirely depends on the number N. The person (Bob or Alice) to arrive at 2 first wins. If N is even, N-2 will be even. The deductions at each step before the number is reduced by subtractions to 2 must all add upto N-2, in which case we can have an even number of odd terms(terms which are deduced at each step), or an even number of even terms, but never an odd number of odd or even terms, that add up to N-2. If Alice starts at an even number, it would therefore take an even number of deductions for Alice to arrive at 2, in which case Alice wins obviously. If he starts at an odd number, it means that Bob will start at an even number, and consequently he wins. So, its just a matter of finding out if the number given is odd or even.

    Will it be called an optimal

    stonu @ 18 Jun 2012 06:24 PM
    Will it be called an optimal strategy to present the next person with an odd number wherever possible, for example, if Alice is at an even number, he will subtract from it an odd factor of it so that the resulting number is odd for Bob? Of course, if he is at an odd number, he has no choice but to subtract an odd number

    Nice one... really enjoyed

    krooonal @ 26 Aug 2012 11:41 AM
    Nice one... really enjoyed after knowing the exact solution...

    what is the meaning of

    justme686 @ 17 Sep 2012 07:19 PM
    what is the meaning of optimally???????? plz help:))

    Clever Problem :)

    tr4n2uil @ 26 Sep 2012 02:46 PM
    Clever Problem :)

    simple super problem

    karthi366 @ 24 Nov 2012 03:44 PM
    simple super problem ............

    Very very nice problem :)

    kiara20 @ 7 Dec 2012 03:14 PM
    Very very nice problem :)

    shortest code i ever made on

    blade_21 @ 25 Dec 2012 11:23 PM
    shortest code i ever made on codechef :)

    one line logic....

    anil09 @ 23 Jan 2013 12:12 PM
    one line logic....

    For all those who are still

    h2dw @ 25 Jan 2013 05:34 PM
    For all those who are still in the dark, i have three suggestions:- 1. Please read the basic tutorial on game theory on Codechef. 2. odd-odd=even 3. Spend a few minutes thinking how both 1 and 2 are related. You will appreciate it later.

    Can someone please tell me if

    amitkotha1989 @ 5 Mar 2013 07:34 PM
    Can someone please tell me if i choose N as 12 who will win the game??

    @amitkotha1989 for n=12

    sjsupersumit @ 21 Mar 2013 08:30 AM
    @amitkotha1989 for n=12 alice will win the game. the answer to the problem is damn easy. just analyze the problem carefully.

    Does Optimally means to

    theshaxx @ 27 Mar 2013 05:09 PM
    Does Optimally means to subtract the largest possible divisor? Pz help

    Could you please give a

    vishal_anand93 @ 30 Apr 2013 12:14 PM
    Could you please give a tutorial on this problem, as to why the odd number gives rise to winning of BOB. In game theory, it gives an intuition, but how does that ensure?

    SUCCESSFUL SUBMISSIONS


    Fetching successful submissions

    HELP



    Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

     

    • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.

    • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.

    • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.

    • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.

    • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.

    • If you are still having problems, see a sample solution here.
    CodeChef is a non-commercial competitive programming community
    • About CodeChef
    • About Directi
    • CEO's Corner
    • C-Programming
    • Programming Languages
    • Contact Us
    © 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
    In order to report copyright violations of any kind, send in an email to copyright@codechef.com
    CodeChef a product of Directi
    The time now is:
    CodeChef - A Platform for Aspiring Programmers

    CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

    Practice Section - A Place to hone your 'Computer Programming Skills'

    Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

    Compete - Monthly Programming Contests and Cook-offs

    Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

    Discuss

    Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

    CodeChef Community

    As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

    Go For Gold

    The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.