CODEMANIA PROBLEM "CUPID ME"


above is the problem
here i am not able to think what to do other than finding primes in the given range
Please help
Thanks

After finding no of primes copy paste soln of https://www.codechef.com/KH19MOS/problems/RANDID . Set Q=No of Primes and N=No of non Primes.

Summary

You can read editorial of that Kgp regional problem.

Thanks man.
I got a idea ,to go further.
Did you also solve problem https://www.codechef.com/COMA2020/problems/WORK .
from same contest ,I am just able to think about brute force solution .how can optimise ?
Thanks in advance

Can someone help me understand what’s wrong with this submission of mine?

https://www.codechef.com/viewsolution/29236202

Question link : https://www.codechef.com/COMA2020/problems/ABSEQ

Link to a similar solution that got AC: https://www.codechef.com/viewsolution/29237732

Someone told me that same problem exists on codeforces but Idk exact link.
As far as what we did my teammate just wrote a backtracking soln and test cases were weak af to get AC.

Hey, can you explain, how the expected value is

N + Q - N/(Q+1)