I have written a basic brute force algorithm to check the winning positions using the N,P positions. The game is equivalently the subtraction game with set S={1,2,3} and the rest of the primes are irrelevant.
For a subtraction game(refer to wikipedia) any position with n%(k+1)==1 is a losing position for the current player.
Given that any other number than can be subtracted are primes and all primes are of the form 4n-1 and 4n+1 they can be equivalently replaced by 3 and 1.
Consider total pile to be 8:
Two possible ways are
8->1 (Bob cannot make a move)
Subtracting a prime 7(of the form 4n-1) is equivalently replaced by 3. A total pile of 5 can be given to Bob and since N%4==1 for 5, it is a losing position for Bob.
8->5->4->1
8->5->3->1
8->5->2->1
Hence, any move made by Bob from 5(a losing position) results in him losing.
Go by induction.
hypothesis: Let for n=4p+1, Player whose chance isn’t now wins. And for n=4p+2 or 4p+3 or 4p+4, Player having Chance is the winner.
Base :True for p=0.
step:let
n=4(p+1)+1
i.e. n=4p+5
Now bob will need to subtract something from it so that the resulting no. is of the form 4q+1. To do so, he will have to subtract some integer 4m which is not prime. Hence alice wins.
n=4(p+1)+2 or 4(p+1)+3 or 4(p+1)+4
i.e n=4p+6 or 4p+7 or 4p+8 respectively.
So Bob will subtract 1 or 2 or 3 respectively to get 4p+5 on Alice’s turn.
Now same problem arises for Alice as Bob Hence Bob wins.
NOW NO MATTER WHAT ALICE CHOOSES (E.G. 1, 2, OR 3) SHE WILL LOSE…
IF SHE CHOOSES 1 : 5 - 1 = 4 THEN BOB WILL CHOOSE 3 >>>> RESULT BOB WINS |||
IF SHE CHOOSES 2 : 5 - 2 = 3 THEN BOB WILL CHOOSE 2 >>>> RESULT BOB WINS |||
IF SHE CHOOSES 3 : 5 - 3 = 2 THEN BOB WILL CHOOSE 1 >>>> RESULT BOB WINS
HENCE NO MATTER WHAT ALICE CHOOSES… IT WILL BE INSTANT DEATH FOR HER…