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
    • May Cook-Off
    • May Long 2012
    • April Cook-Off
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » April Long Contest » Number Game Revisited

Number Game Revisited

Problem code: NUMGAME2

  • 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 runs are as follows :

1.Bob plays first and the two players alternate.

2.In his/her turn ,a player can subtract from N any prime number(including 1) less than 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 format:

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

Output format:

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

Example

Sample Input:
2
1
2

Sample Output: ALICE BOB
Constraints: 1 <= T <= 1000000 1 <= N <= 1000000000

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


Date: 2010-11-23
Time limit: 1s
Source limit: 50000
Languages: TCL PERL6 CLOJ GO PYTH 3.1.2 F# C C99 strict C++ 4.0.0-8 C++ 4.3.2 PAS gpc PAS fpc JAVA NICE JAR C# NEM ST ASM D FORT ADA BASH PERL PYTH RUBY LUA ICON PIKE PHP SCM guile SCM qobi LISP sbcl LISP clisp SCALA HASK ERL CAML CLPS PRLG WSPC BF ICK TEXT JS


  • Submit

Comments

  • Login or Register to post a comment.

nice way to make FOOL :)

manoharsingh23 @ 1 Apr 2011 03:10 PM

nice way to make FOOL :)

what OPTIMALLY actually means

saurabhkr.1989 @ 1 Apr 2011 03:42 PM

what OPTIMALLY actually means here...

please explain using N=15??

Optimally here (and

vikeshkhanna @ 1 Apr 2011 04:31 PM

Optimally here (and everywhere) means that both Alice and Bob will try their best to win the game. For e.g., if N=4, Bob can subtract 1, 2 or 3 but he will subtract 3 because that leads to his victory. You can try with N=15 yourself.

I assume this is not a april

acc1 @ 1 Apr 2011 04:54 PM

I assume this is not a april fool joke.(Since this is a reputed site and they care for our time.)

I think this question is way too easier compared to any question that had apeared in any of the past contests( althoug I have not see all of them).

It would have been better if you would have given Fibonacci number instead of prime number.

(that subtraction of fibonacci numbers < N )

Thanks.

Happy fools day, the odd one

udayabhanug @ 1 Apr 2011 05:02 PM

Happy fools day, the odd one out the lot.

Happy fools day. Nice one!!

shreydutta.28 @ 1 Apr 2011 05:58 PM

Happy fools day. Nice one!!

if BOB makes the first move

shankysodhi @ 2 Apr 2011 03:49 PM

if BOB makes the first move in first test case  and substracts 1. Then the remaining no is 0. So alice cant make a move and so BOB should win . So why does the output answer says ALICE. Care to Explain plz ....

@Karanveer In the problem

shyammurarka @ 2 Apr 2011 06:21 PM

@Karanveer In the problem statement, it has been mentioned that "In his/her turn, a player can subtract from N any prime number (including 1) less than N."

Bob cannot subtract 1 in his turn because it is not less than N (which is 1).

k. Thanks shyam . Didnt

shankysodhi @ 2 Apr 2011 07:06 PM

k. Thanks shyam . Didnt notice that.

My logic is correct. I am

bharswami @ 3 Apr 2011 05:57 PM

My logic is correct. I am getting right answer for test cases and a few more. My submission however gives TLE. Care to explain anyone?

@BharathYour program did not

vikeshkhanna @ 4 Apr 2011 02:47 AM

@Bharath
Your program did not finish executing within the specified time limit for this problem. So you get 'Time Limit Exceeded', irrespective of the correctness of your logic.

PLEASE ANY one explain

piyushurpade @ 4 Apr 2011 09:31 AM

PLEASE ANY one explain me

what is mean by OPTIMALLY?

explain for N=5 || n=7;

@piyush Optimally in the

lesley_t @ 4 Apr 2011 05:04 PM
@piyush Optimally in the sense "cleverly" or "accurately". Bob and Alice shouldn't make any mistakes while playing the game. For example, For N=7, Bob can take 1,2,3 or 5 from 7. But upon taking 1,3,5 he would lose the game.(Check it!) So he would take 2 instead to win the game!.

@piyush Optimally in the

lesley_t @ 4 Apr 2011 05:04 PM
@piyush Optimally in the sense "cleverly" or "accurately". Bob and Alice shouldn't make any mistakes while playing the game. For example, For N=7, Bob can take 1,2,3 or 5 from 7. But upon taking 1,3,5 he would lose the game.(Check it!) So he would take 2 instead to win the game!.

Guys i m a noob out here n i

ronakag @ 6 Apr 2011 09:07 PM

Guys i m a noob out here n i m unable to get through the question:

Is it askign for the following?

 

Let a random number has been choosen Say 22

Bob : 19   //New Num : 3

Alice : 2  // New Num : 1

 

Bob cannot subtract anymore so ALICE is winner...

May i correct

Ronak, This is not optimal.

rajiv_adm @ 6 Apr 2011 09:22 PM

Ronak, This is not optimal. If Bob choose 19, Alice can choose 1. Then Bob has to choose 1 and Alice will Win. Thus 19 by Bob is not the optimal move.

@RONK AGRAWAL:

cool123 @ 6 Apr 2011 09:31 PM

@RONK AGRAWAL: BOB:17(5)

ALICE:3(2)

BOB:1

So BOB is the winner !

can any body tell me what may

softmaster @ 7 Apr 2011 06:58 PM

can any body tell me what may be the reason for TLE IN MY submission

please

@Note : For the first test

nikhilsimha @ 7 Apr 2011 11:57 PM

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

i think in the second case BOB loses by substracting 1 and alice still wins(she can substract 1 now).

sorry!^ my bad

nikhilsimha @ 7 Apr 2011 11:59 PM

sorry!^ my bad

if we think

hsnd @ 9 Apr 2011 01:39 PM

if we think optimally...always bobs wins...never alice once except the no is 1.

how i can get ride of time

paulanimesh @ 9 Apr 2011 06:41 PM

how i can get ride of time limit execexed

what  the wrong answer for

paulanimesh @ 10 Apr 2011 06:34 PM

what  the wrong answer for what value

i have more or less figured

abhas12345 @ 11 Apr 2011 10:05 AM
i have more or less figured it out. but still it will take time putting them as codes.. wish my concepts are ok.

can some plz give some test

melwin_jose @ 11 Apr 2011 09:01 PM

can some plz give some test inputs along with itz resultz :)

Hey, can we download ur

akshay_monty @ 17 Apr 2011 12:45 AM
Hey, can we download ur compiler from somewhere so that i can check my solutions b4 submitting???

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
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 computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various 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 judge accepts solutions in over 35+ programming languages. Online programming was 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 competitions 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 programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

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. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef 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.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com