## MAGMA Interview Question for Software Engineer / Developers

Comment hidden because of low score. Click to expand.
2
of 2 vote

use formula

no=(a/5^1)+(a/5^2)+.......

where no=number of zero
a=no. for which no.of zeros is to be calculated

take only int value of no.

Comment hidden because of low score. Click to expand.
0

using above formula we get
100! has 24 zeros
1000! has 249 zeros

etc

Comment hidden because of low score. Click to expand.
1
of 1 vote

Each occurence of 5 with an even number gives the 0 at the end.
So, in 100!, first find the occurences of 5 . i.e. how many powers of 5 are contained in 100!

Powers of 5 in 100! = 100/5 + 100/(5^2) + 100/(5^3) + .....
= 20 + 4 + 0..
= 24

SO the ans is 24.
@avatarz: 100! = 9.33262154 × 10 ^ 157 is the way of representing the final ans but it does not provide the 0s at the end.

For ex: 1930000 can be written as 1.93 * 10^6 or 19.3 * 10^5 or 193 * 10^4.... it's not giving the no. of 0s at the end.

Comment hidden because of low score. Click to expand.
0
of 0 vote

found one more.... when there is zeros at unit place, 2 or 4 or 6 with 5 at tens will contribute to one more zero.. Thus total zeros are 22....

Comment hidden because of low score. Click to expand.
0
of 0 vote

the number of 0s in n! is the power of 5 in the prime factorization of n
n! = 2^k1 * 3^k2 * 5^k3 * 7^k4 * ...
to get k3, one will have to:

``````k3 = 0
for i=5:n
j = i
while j % 5 == 0
k3++
j /= 5
return k3``````

Time complexity:
O(n) = sum over i (log_5 i) <= n * log_5(n) = O(n * log_5 n)

Comment hidden because of low score. Click to expand.
0

puzzles.nigelcoldwell.co.uk/nineteen.htm.
you could generalize it to :: (floor)(n/25) + (floor)(n/5)

Comment hidden because of low score. Click to expand.
0
of 0 vote

answer is 24 because 1 zero is added for every factorial of a multiples of 5 and 2 zeros are added for multiples of 25

Comment hidden because of low score. Click to expand.
0
of 0 vote

50! alone has 50 zeros!!! Just use excel and try it out..

Comment hidden because of low score. Click to expand.
0
of 0 vote

Each occurence of 5 with an even number gives the 0 at the end.
So, in 100!, first find the occurences of 5 . i.e. how many powers of 5 are contained in 100!

Powers of 5 in 100! = 100/5 + 100/(5^2) + 100/(5^3) + .....
= 20 + 4 + 0..
= 24

SO the ans is 24.
@avatarz: 100! = 9.33262154 × 10 ^ 157 is the way of representing the final ans but it does not provide the 0s at the end.

For ex: 1930000 can be written as 1.93 * 10^6 or 19.3 * 10^5 or 193 * 10^4.... it's not giving the no. of 0s at the end.

Comment hidden because of low score. Click to expand.
0
of 0 vote

if you search in wolfram alpha, it gives an answer of 30 zeros, 24 is the last zeros, there are other zeros inside,I did not understand

Comment hidden because of low score. Click to expand.
0
of 0 vote

A function E(p){n!}=[n/p]+[n/p^2]+[n/p^3]+.... where (p) is the prime factor. Eg: 10 = 2, 5. Prime factor. So, P =2,5.The soln is as follows: Prime factors of 10=2*5 and E(2){50!}=[50/2]+[50/4]+[50/8]+[50/16]+[… or E(2){50!}=47 and E(5){50!}=[50/5]+[50/25]+[50/125] or E(5){50!}=12. Then E(10){50!}=the number of zeros in 50!=min of (47,12). Hence number of zeros in 50! is 12.

Comment hidden because of low score. Click to expand.
0
of 0 vote

A function E(p){n!}=[n/p]+[n/p^2]+[n/p^3]+.... where (p) is the prime factor. Eg: 10 = 2, 5. Prime factor. So, P =2,5.The soln is as follows: Prime factors of 10=2*5 and E(2){50!}=[50/2]+[50/4]+[50/8]+[50/16]+[… or E(2){50!}=47 and E(5){50!}=[50/5]+[50/25]+[50/125] or E(5){50!}=12. Then E(10){50!}=the number of zeros in 50!=min of (47,12). Hence number of zeros in 50! is 12.

Comment hidden because of low score. Click to expand.
-1
of 1 vote

100! = 1x2x3x..x98x99x100
all the zeros at unit places and 5*2 or (5*4) will contribute towards number of zeros.
11 zeros - for zeros at unit place
10 zeros - for (5*2) or (5*4)

Total 21 zeros.........

Comment hidden because of low score. Click to expand.
-1
of 1 vote

with 100 there are 20 number with facter 5, and 4 number with factor 25. So there are 24 zeros in 100!.

Comment hidden because of low score. Click to expand.
-1
of 1 vote

100 has two zeros!!! one 1 and two 0---100

Comment hidden because of low score. Click to expand.
-1
of 1 vote

100 ! = 9.33262154 × 10 ^ 157

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.