How to solve this Problem ? Any solution in C++ will be more helpful . Thanks in advance

Take time and try to solve it on your own, if you donâ€™t get it have a look at the editorial. The problems you are asking are from medium level, so itâ€™ll take some time to solve them. Donâ€™t just ask questions without trying them.

First have a look at the editorial:- Click Here

This should help.

Its another typical segmented sieve problem, with a bit of greedy.

Given the value for A and B, you first segment out prime and not prime numbers. For every number `i`

, instead of marking/storing `1`

for non-prime, you store the factor of that number at that position. Its preferable to use a vector, such that `vec[i] is storing all the factors of that number`

\le {10}^{6} In case there is nothing stored in the factor list, or the multiplication of factors does not yield the original number, then you can claim that the `leftover number`

is prime.

Eg, take case of 38.

We store only {2} in vector. After diving by 2, 19 is left. My claim is, since we stored all factors \le \sqrt{N}, and there is no more factor except 2 in vector, and that since ProductOfFactors!=38, \implies 19 is leftover-and this leftover is prime itself.

Now whats left is just finding a way to maximize result from the factors- the editorial has given 2 beautiful proofs that how greedy works here and how to apply it. I hope this addressed the issue here.

Well, I would have recommended testerâ€™s code, but idk that link suddenly broke. I will get it fixed asap though.

Question:- PRIME1

Both are exactly same!!! @harrypotter0 You asked this question in the morning and you just copied it from @vijju123 and submitted it. Donâ€™t post questions if youâ€™re going to copy anyway from other users. If you donâ€™t get it, try it after few days then you have a chance of getting it. This is not good bro. Please donâ€™t repeat it again.

Already invested 3-4 hours on the problem â€¦

Watched that but still stuck

Actually I didnâ€™t copied . Please check I got it accepted before testing his solution :0

Testing my solution?

Testing :: By removing else condition , it fails for larger inputs so I came to know that without modification one canâ€™t pass all test cases .

Oh XDXD. Experimenting is always good . But you need a legible code for that