How many zeros are at the end of "100!"?
Answer: The trick is remembering that the number of zeros at the end of a number is equal to the number of times "10"(or "2*5")appears when you factor the number. Therefore think about the prime factorization of 100! and how many 2s and 5s there are.
so the number of 5s is also the number of 10s in thefactorization.There is one 5 for every factor of 5 in our factorial multiplication(1*2*...*5*...*10*...*15*...) and an extra 5 for 25, 50, 75, and100. Therefore we have 20+4=24 zeros at the end of 100!.
Refer : http://en.wikipedia.org/wiki/Horner_scheme Answer: The trick is remembering that the number of zeros at the end of a number is equal to the number of times "10"(or "2*5")appears when you factor the number. Therefore think about the prime factorization of 100! and how many 2s and 5s there are.
so the number of 5s is also the number of 10s in thefactorization.There is one 5 for every factor of 5 in our factorial multiplication(1*2*...*5*...*10*...*15*...) and an extra 5 for 25, 50, 75, and100. Therefore we have 20+4=24 zeros at the end of 100!.
The minimum number of multiplications required to evaluate the expression a + bx + cx2 + dx3 + ex4 is
a+bx+cx2+dx3+ex4
a+x(b+cx+dx2+ex3)
a+x(b+x(c+dx+ex2))
a+x(b+x(c+x(d+ex)))
a+x(b+x(c+x(d+(e*x))))
Number of brackets(4) represent the multiplications required.
Horner's Rule :
A rule for polynomial computation which both reduces the number of necessary multiplications and results in less numerical instability due to potential subtraction of one large number from another. The rule simply factors out powers of x, giving
a+bx+cx2+dx3+ex4
a+x(b+cx+dx2+ex3)
a+x(b+x(c+dx+ex2))
a+x(b+x(c+x(d+ex)))
a+x(b+x(c+x(d+(e*x))))
Number of brackets(4) represent the multiplications required.
Horner's Rule :
A rule for polynomial computation which both reduces the number of necessary multiplications and results in less numerical instability due to potential subtraction of one large number from another. The rule simply factors out powers of x, giving
Java Code :
public class NumberOfZeros {
public static void main(String[] args) {
int n = 100;
int x10 = 0;
int x5 = 0;
int x25 = 0;
for (int i = 1; i <= n; i++) {
if (i % 10 == 0)
x10++;
else if (i % 5 == 0)
x5++;
if (i % 25 == 0)
x25++;
}
int totalNumberOfZeros = (x10 + x5 + x25);
System.out.println("Total number of zeros : " + totalNumberOfZeros);
}
}
No comments:
Post a Comment