How to Solve PRIME1 question?

what are the approaches to solve prime1 question

1 Like

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

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 of solution


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

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:


yes u must be knowing better. :smiley: