Speed up bitstring/bit operations in Python?

There are a couple of small optimizations for your version. By reversing the roles of True and False, you can change “if flags[i] is False:” to “if flags[i]:“. And the starting value for the second range statement can be i*i instead of i*3. Your original version takes 0.166 seconds on my system. With those changes, … Read more

Calculating and printing the nth prime number

To calculate the n-th prime, I know two main variants. The straightforward way That is to count all the primes starting from 2 as you find them until you have reached the desired nth. This can be done with different levels of sophistication and efficiency, and there are two conceptually different ways to do it. … Read more

Fast Prime Number Generation in Clojure

Here’s another approach that celebrates Clojure’s Java interop. This takes 374ms on a 2.4 Ghz Core 2 Duo (running single-threaded). I let the efficient Miller-Rabin implementation in Java’s BigInteger#isProbablePrime deal with the primality check. (def certainty 5) (defn prime? [n] (.isProbablePrime (BigInteger/valueOf n) certainty)) (concat [2] (take 10001 (filter prime? (take-nth 2 (range 1 Integer/MAX_VALUE))))) … Read more

How many prime numbers are there (available for RSA encryption)?

RSA doesn’t pick from a list of known primes: it generates a new very large number, then applies an algorithm to find a nearby number that is almost certainly prime. See this useful description of large prime generation): The standard way to generate big prime numbers is to take a preselected random number of the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)