Created
April 23, 2011 13:31
-
-
Save rohit-nsit08/938611 to your computer and use it in GitHub Desktop.
codechef-april
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Problem description | |
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 ? | |
*/ | |
/*solution*/ | |
#include<stdio.h> | |
int main(void) | |
{ | |
int testcases,input,lost_check; | |
scanf("%d",&testcases); | |
while(testcases>0) | |
{ | |
lost_check = 0; | |
scanf("%d",&input); | |
if(input==1) | |
{ | |
lost_check =1; | |
} | |
else if((input-1)%4==0) | |
{ | |
lost_check = 1; | |
} | |
if(lost_check) | |
printf("ALICE\n"); | |
else | |
printf("BOB\n"); | |
testcases--; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment