{ p 1 , p 2 , p 3 , … , p n , … } is the set of primes. f ( n ) = i = 1 ∏ n p i What are the last three digits of f ( 2 0 1 4 ) ?
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.
Image Source:Wikipedia commons
Really I don't think a solution exists without programming here. This question should have been posted in Computer Science.
Log in to reply
Yes I think so too,Isnt this a CS problem?
Log in to reply
It is a Comp Sci problem. I put tags on it that would indicate so, but those aren't showing up for now. Logan Dymond made a post requesting the ability to classify problems, and the Brilliant staff said that is something they are working on.
You can also make a prime array
prime
with some starting primes and then adding primes to it after testing the next number (using a
for
loop) for primality by trial division from
prime[0]
to
prime[k]
where
prime[k]
≤
⌊
n
⌋
(
n
is the number being tested). If
n
is prime, it's added to the array. Keeping count, we do this till we get
2
0
1
4
primes in
prime
and then it's simple modular calculation.
Here 's my C++ implementation of the above idea (runs in 0.14 sec).
Although, maybe this is equivalent to using Sieve of Eratosthenes if we compare execution time (?).
Log in to reply
Yes, that method is also equally valid. The Sieve is slightly superior because it runs in O ( n l o g ( l o g ( n ) ) ) time. I think the trial division approach can be bound by 1 + 2 + 3 . . n < ∫ k = 0 n x 0 . 5 = O ( n 1 . 5 ) . The trial division method can be refined to faster non-deterministic tests like miller rabin .
No way to solve this except brute force, so that's what I did, hehe. Here's the PARI/GP program:
(prod(k=1,2014,prime(k)))%1000
PARI/GP strikes again, you are the man ^^
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Problem Loading...
Note Loading...
Set Loading...
Visual Sieve of Erastothenes
I used the sieve of Eratosthenes to generate all the primes below 1 0 5 .I then computed every product modulo 1 0 3 just to keep track of the last three digits. A visual explanation of the Sieve is given above.
The sieve can be implemented easily but this snippet from stackoverflow is the fastest version I know of.