vickybat
I am the night...I am...
nope, still not running.. ideone says time limit exceeded while python 2.6 on my computer does not produce any output even after few minutes.
OKAY it took 15 minutes on my PC to complete the code(not sure if my PC is slow or the code). . mate, companies will kick me out for compiling this question in 15 minutes. Let's try a better algorithm
Yup its taking a lot of time in python. My earlier Java code takes just over a second to complete. Dunno why the same logic is so slow in python.
Try copy pasting my java code in an eclipse or netbeans ide. It will generate output in just over a second. Divisibility checks are the slowest form of computation.
That said, chaitanya's code is extremely optimised. That's because he uses the sieve of eratosthenes algorithm to generate primes and stores them in an array.
The SOE algorithm does not has any form of divisibility check to determine primes. It relies on striking out the multiples of prime numbers in each iteration and the numbers left out are primes.No divisibilty check per iterartion here.
Then he compares the highest power of each prime with the largest range, then multiplies them in each iteration. So the LCM of all these numbers gives the resultant output.
I'm trying a simplified boolean function in java that does the same thing but much simplified. Didn't quite get the time today, but will post soon as its complete.
Chaitanya's method is highly optimized and even OP should consider this in C++.
P.S= What are your PC specs??
Last edited: