e .
Find the first 10-digit prime number that is found in consecutive digits ofBackground: The tech giant Google is known to have setup such billboards in the heart of Silicon Valley, and later in Cambridge, Massachusetts; Seattle, Washington; and Austin, Texas. It read
" {first 10-digit prime found in consecutive digits of e}.com ".
Solving this problem and visiting the website led to an even more difficult problem to solve, which in turn led to Google Labs where the visitor was invited to submit a resume. Unfortunately, that website has been taken down.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Good Job!
By the way:
Due to time limitations,we cannot use conventional methods to check if a ten digit number is prime or not.
What method is that?
The most common test(Checking if any number from 2 to n divides the number) or Fermat's primality test.
How do you do syntax coloring in your code?
@Agnishom Chattopadhyay – Look at this
One can program it with other languages too but it is done pretty straightforward with Mathematica.
FromDigits[#] & /@
Partition[RealDigits[E - 2, 10, 1000] // First, 10, 1];
Select[%, PrimeQ] // First
The first line of the code selects all strings of length 10 from the first 1000 consecutive digits of e. Much Like this: {7182818284, 1828182845, 8281828459, 2818284590 ... }.
The second line of the code Selects the elements of the list which are primes and returns the First one.
When run, the code returns:
7 4 2 7 4 6 6 3 9 1
By the way, if you do not believe that Google really did this: Please read this
Solution Courtsey: @bobbym none
By the way, the problem is inspired by this discussion.
I'm just speechless. In one single day, your question has slid from level 5 to level 1, all thanks to google ;)
Yeah, its pretty disheartning!
This Problem would not have lost its rating if it had one. Mainly because, the answer is not on Google.
An easy way to do it in Mathematica without the need to convert digits to strings and then back:
Select[Table[Floor[Mod[E*10^(10+n), 10^10]], {n, 0, 100}], PrimeQ]
If you multiply e by 10^10 then take its residue of modulo 10^10, you get the first ten digits after the decimal place as an integer. Repeat by multiplying by successively larger multiples of 10 until the prime is discovered.
Java solution -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Execution time ~ 0.003239731 seconds (without time taken to read the e file)
Method to read e -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Problem Loading...
Note Loading...
Set Loading...
I used continued fractions. We first change e into its continued fraction representation:
e = [ 2 ; 1 , 2 , 1 , 1 , 4 , 1 , 1 , 6 , 1 , 1 , 8 , … ] .
We can find the 1 0 0 t h convergent fraction approximation of e :
e ≈ 5 0 8 5 5 2 5 4 5 3 4 6 0 1 8 6 3 0 1 7 7 7 8 6 7 5 2 9 9 6 2 6 5 5 8 5 9 5 3 8 0 1 1 6 2 6 6 3 1 0 6 6 0 5 5 1 1 1 3 6 5 2 8 4 0 5 2 1 3 8 6 3 9 7 7 7 0 7 7 5 9 3 0 2 2 9 5 3 3 5 9 6 1 7 1 2 9 6 1 6 7 7 8 3 9 1 0 9 0 4 5 5 5 9 0 9
This approximation turns out to be sufficient for finding the required prime.
Due to time limitations, we cannot use conventional methods to check if a ten digit number is prime or not, therefore I used the Miller-Rabin primality test to quickly check for primality.
Here is the final code in python: