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.

- sandy880 February 20, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

etc

- sandy880 February 20, 2011 | Flag
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.

- Santosh December 16, 2011 | Flag Reply
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....

- Anonymous February 16, 2011 | Flag Reply
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)
log_5 i = log in base 5 of i

- S February 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- blueskin.neo February 17, 2011 | Flag
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

- abhishek February 20, 2011 | Flag Reply
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..

- sky June 02, 2011 | Flag Reply
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.

- Santosh December 16, 2011 | Flag Reply
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

- ygfster March 16, 2012 | Flag Reply
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.

- anonymous March 17, 2012 | Flag Reply
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.

- anonymous March 17, 2012 | Flag Reply
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.........

- Anonymous February 16, 2011 | Flag Reply
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!.

- Anonymous February 16, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

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

- bylike March 04, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Google it...and you get this answer :
100 ! = 9.33262154 × 10 ^ 157

- avatarz October 10, 2011 | Flag Reply


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More