How to Solve PRIME1 question?

what are the approaches to solve prime1 question
PRIME1

1 Like

For solving this kind of question Sieve algorithms is one of the best way to solve
you can check my complete solution

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

first store all the prime numbers from 1 to 10^6 using sieve

And you have give that (n-m<=100000)

Then iterate all the numbers form n to m and use stored prime numbers for check the num is prime or not.

Example take n = 1234567 , m = 1235678

for num = 1234567 , check its a prime num or not for this iterate all the prime numbers upto < sqrt( 1234567) if any prime num divides 1234567 then its not prime , else prime num.

this is the link https://www.codechef.com/viewsolution/11824047 of solution

2 Likes

a common method for this one, just go through this one.

https://www.youtube.com/watch?v=eKp56OLhoQs

for better undersatnding.

why have the guys upvoted this question? for upvotes?

@raj79 It’s a loop… every one is doing this now on this platform… how is it feeling now?? :smiley: :stuck_out_tongue:

2 Likes

yes u must be knowing better. :smiley: