Find the minimum integer n such that the number of trailing zeroes of ( n + 2 0 ) ! × ( n + 1 5 ) ! is divisible by 2015.
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.
I think for n=2480, the statement holds true
Log in to reply
Then we'll get only 6 2 4 + 6 2 0 = 1 2 4 4 trailing zeroes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Even it is not allowed to solve it with code, the code is not short neither effective.
def lead(a, b = 0):
while a:
a//=5
b+=a
return b
n=0
while (lead(n+15)+lead(n+20))%2015 != 0:
n+=5
Log in to reply
Or:
1 2 3 4 5 6 7 8 9 10 11 |
|
Log in to reply
I dont know. I've remembered the reason why I used dynamic programming in here - it was used in original code and I decided to do it shortly. Technically, python is quite bad with recursion, so it is much more efficient to use direct way. Also, (total%2015 !=0) equals to (not (total%2015)) and I am not sure which one is faster. in second while where you have ==0 you can just delete it - it will mean the same, the * thing is quite slow in python too - you could save the temporary result of powering. Also you can divide n by 5 strictly, cause n will be divided by 5 and have (n//5+4)%(5 *partial). In fact, the time for optimizing could be pretty long, but nobody wants to spend unnecessary time on polishing code for 1 time, which runs faster than a sec.
You are right, I think there could be some improvments in actually both. Can you explain how you did the python code tag? I used python and nothing happend. Time of your code on 10**5 repeats - 0.0010250341749191284. My code - 0.0014282305192947387 .
Problem Loading...
Note Loading...
Set Loading...
Let the trailing zeros of m ! be f ( m ) ; the exact formula is given by Lengendre's formula
f ( m ) = k = 1 ∑ ∞ ⌊ 5 k m ⌋
We can approximate our desired n by ignoring the floor function:
k = 1 ∑ ∞ 5 k n + 2 0 + 5 k n + 1 5 = ( 1 − 5 1 1 − 1 ) ( n + 2 0 + n + 1 5 ) = 4 2 n + 3 5 > 2 0 1 5 a
Now, testing with a = 1 , we get n ≥ 4 0 1 3 . Plugging in n = 4 0 1 3 , f ( 4 0 1 3 + 2 0 ) + f ( 4 0 1 3 + 1 5 ) = 2 0 1 1 . Increasing by 2 × 5 to n = 4 0 2 3 gives f ( 4 0 1 3 + 2 0 ) + f ( 4 0 1 3 + 1 5 ) = 2 0 1 5 for an upper bound; we know also now that n exists for a = 1 .
Finally, after a while, after looking at smaller and smaller n (or alternatively, by noting that 5 ∣ 4 0 2 0 ), we see that n = 4 0 2 0 is our desired minimum.