• TwitterFacebookGoogle PlusLinkedInRSS FeedEmail

Spiral Primes Problem 58

01.02.2020 

Hi SuprDewdI saw your Rabin-Miller implementation and I think that the main difference is that I implemented the modular power method while you use the one that comes with the BigInteger class.The BigInteger class definitely has performance issues compared to the integral types like int and longs. However, in cases where you would normally use Rabin-Miller for testing primality – such as cryptology – the numbers are so large that you would need the BigInteger class. So I don’t think there is anything wrong with the implementation you made./Kristian. I found this terrifically useful for my Python solution, which runs in 2 seconds after paring away tons of needless complexity: from future import divisionimport copyfrom myeuler import.def proportionofprimes(totalprimes, n):return totalprimes / ((n - 1). 4 + 1)n = 2lastcorner = 9totalprimes = 3while proportionofprimes(totalprimes, n) 0.1:n += 1for i in xrange(4):lastcorner = lastcorner + (n - 1). 2if isprime(lastcorner):totalprimes += 1# side length is desiredprint 2. n - 1.

  1. Spiral Primes Problem 58 Inch

Great blog I use to read you and dreamshire to get a better insight in Project Euler problems and at the time I read this problem I knew it was necessary to use a “primality test”, but after reading and get Fermat Primality Test and later Miller-Rabin Primality Test, I failed to test it manually I had to see it in code, and it really helped worked like a charm.Submitting the answer was a little bit bittersweet, but I prefer to think that I learnt something instead of the taste of cheating hehehe.Thanks!

Spiral Primes Problem 58 Inch

Spiral Primes Problem 58

Problem 58:Starting with 1 and spiralling anticlockwise in the following way, a square spiral with side length 7 is formed. 37 36 35 34 17 16 15 18 5 4 3 12 2940 19 6 1 2 11 2841 20 7 8 9 10 2742 21 22 23  44 45 46 47 48 49It is interesting to note that the odd squares lie along the bottom right diagonal, but what is more interesting is that 8 out of the 13 numbers lying along both diagonals are prime; that is, a ratio of 8/13  62%.If one complete new layer is wrapped around the spiral above, a square spiral with side length 9 will be formed.

If this process is continued, what is the side length of the square spiral for which the ratio of primes along both diagonals first falls below 10%? Idea:Even though I already have a spiral generating method used in, I don’t need to generate anything: the diagonals are easily recognized by a pattern of numbers equally spaced apart per layer.

Determine which numbers are on a diagonal, check to see if it’s prime, and keep track of the total numbers on the diagonal. While the ratio of primes along the diagonals to the total number of numbers along the diagonal is greater than 10%, keep adding a new layer.