What's wrong with my SPOJ solution
For once I want to quote myself ...
numerix wrote:Let's see, maybe I'll try a solution ...
The SPOJ prime number task had done it to me. After initially I didn't want to believe that the task with Python could even be accomplished in the maximum specified runtime of 6 s - after all, this is about the calculation of some 10,000 prime numbers from intervals of size 100,000 in the number range up to 1 billion - BlackJack has yes posted a link that leads to the fastest Python solutions and there you could marvel that it is actually possible to write a Python program that solves the problem in 0.41 s! * Could * mind you, because now there's an even faster one, and that's mine - :
Apart from the fact that one can even advance into these temporal areas, the most astonishing thing for me was that the solution (at least mine - I don't know that of the others) is not characterized by a terribly complex algorithm, but by an intelligent use of the Sieves of the Eratothenes. The core algorithm comprises just 10 lines of code.
At first I thought you needed some highly specialized expert algorithm and after some googling and wikipeding you will of course find them. But they were all so complicated for me that I didn't feel like thinking seriously about them. Instead, I spent a few hours with paper and pencil and experimented with the more than 2000 year old sieve des Eratothenes.
This enables a program with a runtime of well under 1 second that is approx. 30-40 lines long. For the last hundredths of a second you have to tinker for a while and try out different - apparently equivalent, but differently performing - variants of individual parts.
Thanks to Graf Wasserrutsche: It was fun!
- Why is fractional distillation used
- How sadistic are you
- Why is Yelp only worth 500 million
- What's your strangest cocktail recipe
- How is Freshman Housing at Hope College
- What is 4x 4 8
- Who took the JEE exams
- What is the definition of a Gentile
- How can POS systems v m n
- Which is better Salesforce CRM or SugarCRM
- What distinguishes the Tableau software
- What is the importance of osmosis 1
- Taylor Swift is a country artist
- What are the cutest names for girls
- Can babies eat nuts?
- How do predators manage to eat porcupines?
- Was the downsizing film a success
- Why shouldn't I buy a smartphone?
- Which animals cannot see the sun?
- What are some proposed real estate developments
- Is it illegal to download from a magnetic link?
- Guaranteed grammar free grammar mistakes
- What is cross-platform development
- What if our universe were 2D
- Which subject is hard physics or biology
- The engineering has a large scope
- What agriculture is practiced in Arunachal Pradesh
- How does the voltage increase with a resistance
- What is the standard of living
- Who banned Huawei
- What makes a theory a good theory
- Which graphics card supports 4k games
- What are some competitive advantages in business
- Trees talk to each other