Let f ( n , k ) be the number of zeroes at the end of n ! in base k .
Let g ( r ) = f ( r , 2 ) + f ( r , 3 ) + f ( r , 4 ) + . . . + f ( r , r )
Find g ( 1 0 0 )
----- Examples -----
f ( 1 0 0 , 1 0 ) = 2 4
f ( 5 3 , 7 ) = 8
f ( 5 , 1 6 ) = 0
g ( 7 ) = 1 2
g ( 2 5 ) = 1 3 6
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.
@Raghav Vaidyanathan , @Pranjal Jain , @Agnishom Chattopadhyay , my programming friends will enjoy this a lot...
Cool question @Jackson Abascal
Log in to reply
Thanks for the tag. I did the sme thing in haskell
f(5,16) should be 0
The following is Aditya's solution, just translated to haskell:
1 2 3 4 5 6 7 8 |
|
MATLAB Code : :
function y=factzero_inbase(n,k)
f = factor(k);
fu = unique(f);
i=1;
while i<=length(fu)
z(i)=0;
j=fu(i);
while j<=n
z(i)=z(i)+fix(n/j);
j=j*fu(i);
end
z(i)=fix(z(i)/length(find(f==fu(i))));
i=i+1;
end
y = min(z);
end
This is very easy in Mathematica :-)
1 2 |
|
Factorize each number from 2 to n (100 in this case) and factorize n!. Then, with that results, we can easily calculate f(n, i).
Note: code written in Boo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
Problem Loading...
Note Loading...
Set Loading...
This is something like "Maths+Programming".
See that number of zeroes at end of n ! in base k will be same as the maximum exponent of k in n ! .
Hence, finding maximum power of k that divides n ! will give us f ( n , k ) .
By asking m a x ( l i ) in this program, we get maximum power of k that divides n ! .
Now this is for g ( r )
This returns g ( 1 0 0 ) = 1 2 9 9 , in a very short time...