Hey Shulei,
I am assuming you wanted two prime numbers and with the following conditions:
- M/2<p1<M
- 2<p2<M
I suggest you use the primes() function to generate a vector of prime numbers upto M and then you write a simple code to choose your p1 and p2 from the vector according to the conditions.