I'm trying to get the first 10-digit prime number using the lazy lists. Here is my take based on the (already given) code for computing the prime numbers:
my @primes = 2,3,5, {first * %% none(@_), (@_[*-1] ... Inf)} ... -> $s {$s.chars == 10};
say @primes[@primes.elems-1];
The problem with that code is that it takes too long to finish.
Is there any quick method to get that first 10-digit prime number?
Python Program for prime numberInitialize a for loop starting from 2 ending at the integer value of the floor of the square root of the number. Check if the number is divisible by 2. Repeat till the square root of the number is checked for. In case, the number is divisible by any of the numbers, the number is not ...
Next to some nine digits numbers, this shows that 7 427 466 391 is the first 10- digit prime in e.
You can make it faster by:
is-prime
method rather than a hand-rolled algorithmThus getting:
say (1_000_000_000..*).first(*.is-prime)
Which produces:
1000000007
You could filter out evens too, but I suspect is-prime
rejects those as fast as you'd separately test them anyway. (Also, it turns out the number is so close to the first 10-digit number that nothing aside from stating at 1_000_000_000
matters in practice.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With