Pages

Monday, 19 January 2015

SPOJ PROBLEM 2:PRIME GENERATOR

Problem Link: http://www.spoj.com/problems/PRIME1/

SUMMARY

Given an interval [m,n] where 1\leq m\leq n\leq 10^{9} and n-m\leq 100000, find all prime numbers in that interval.

Logic:
No composite number less than or equal to n will have a factor greater than \lfloor {\sqrt  {n}}\rfloor so we only need to know all primes up to this limit, which is no greater than 31622 (square root of 109).

To view my solution:

https://github.com/shivam04/spoj/blob/master/PRIME1.cpp

No comments:

Post a Comment