+ 6

[CHALLENGE 2] Trailing zeros in factorial

Sample Input 5 Output 1 Because the factorial of 5 is 120 (5*4*3*2*1) so there are 1 zero in it so output is 1 [ UPDATE ] You need to find only trailing zeros means zeros in the ending of number example 1020 output must be 1 Rules : Complexity must be O(n) You can't find factorial of number by loop or recursion Max input 10^6

17th Dec 2017, 4:08 AM
Ronak Pareek
Ronak Pareek - avatar
18 Réponses
+ 9
my mathematical explanation ... //let U have any number ... take it n! , & U want to find maximum value of x such that n!%3^x=0 , now how will u find value of x ... let n! be 100! //just for better explanation , i hv taken that 100 . 99 . 98 . 97 .96 .......1 //we see there are total 33 numbers which are div. by 3 //we see there are total 11 numbers which are div. by 9 //we see there are total 3 numbers which are div. by 27 // & only 1 number which is div by 81 //its obvious to say that max value of x will be 33+11+3+1 =48 //but do u noticed [100/3]=33 , [33/3] =11 , [11/3] is 3 & [3/3] is 1 //[.] denotes g.i.f (greatest integer function) //similarily u can calculate max y for which n!%2^y =0 //& its obvious that y>x , //note that this is only valid for prime & u know the reason ... if not then think //👉suppose now u want to find max value of k for which , n!%6^k =0 //u know 6 is not prime ... but u can express it in prime ... we need one2 & one 3 //x will be the answer //ie k will be equal to x ☺ 👉U can do many modifications in it ... to solve advance level problems also ... hahaha
23rd Dec 2017, 10:18 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 26
here is my answer for the updated question (trailing zeroes) ☺ https://code.sololearn.com/cWdLm6REukm3/?ref=app
18th Dec 2017, 8:11 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 20
here is my try to the problem☺ //no loops used ☺ https://code.sololearn.com/cGPhOX1ROw5A/?ref=app
17th Dec 2017, 7:41 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 18
GAME IS OVER //let me introduce to U my first java-1liner code ☺ , for the first time //@everyone , my answer don't need any loop.... see pegasus answer its using loop ... while loop //try my code again ... maths is best ☺☺☺ //works till very big value here is my answer for the updated question (trailing zeroes) ☺ https://code.sololearn.com/cWdLm6REukm3/?ref=app
23rd Dec 2017, 11:02 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
17th Dec 2017, 4:48 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 12
https://code.sololearn.com/cvahzY9m7Q0g/?ref=app
17th Dec 2017, 6:52 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 10
My answer to the updated question (trailing zeroes) : https://code.sololearn.com/cvth23x6QKh0/?ref=app
18th Dec 2017, 7:41 AM
LukArToDo
LukArToDo - avatar
+ 9
https://code.sololearn.com/cR4UdxXq945Q/?ref=app
17th Dec 2017, 6:19 PM
LukArToDo
LukArToDo - avatar
18th Dec 2017, 9:31 AM
Divesh Singh
Divesh Singh - avatar
+ 6
Lemme give a mathematical answer: The no. of 5s in the product is always<=no. of 2s. Hence, the answer is simply: floor(n/5)+floor(n/25)+floor(n/125)+.... Now I will make an implementation Edit: https://code.sololearn.com/cC2TvoTmOZo5/?ref=app Maths made this possible, works even beyond your limit
19th Dec 2017, 2:44 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
25th Dec 2017, 7:22 AM
Qwqwq Rt
Qwqwq Rt - avatar
23rd Dec 2017, 10:35 AM
Saurabh Tiwari
Saurabh Tiwari - avatar
17th Dec 2017, 5:46 AM
#RahulVerma
#RahulVerma - avatar
18th Dec 2017, 10:07 AM
Hamid
Hamid - avatar
+ 2
check this one , it's my attempt in java 👍 https://code.sololearn.com/cD3WU69VRmW7/?ref=app
17th Dec 2017, 5:30 AM
Hrishikesh Kulkarni
Hrishikesh Kulkarni - avatar
17th Dec 2017, 9:47 AM
Rishabh Agrawal
Rishabh Agrawal - avatar
+ 2
https://code.sololearn.com/cJdTN8F3Yrq8/?ref=app
20th Feb 2018, 7:10 PM
...
17th Oct 2018, 11:43 AM
Kodola Andrii
Kodola Andrii - avatar