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.