{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lab3 - Java Programming Lab 3!5 k =1 Question 1 Quick Rule...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Java Programming Lab 3 Question 1: Quick Rule for Final Zeros in a Factorial Follow-Up: From our class discussion, the number of final zeros in n ! was seen to be: FZ ( n ) = n 5 k ! " ! # $ # k = 1 % & where the brackets denote the floor function. The infinite sum can be truncated as soon as 5 k exceeds n , as all the subsequent terms are zero. In Java, the floor function is automatically obtained by computing the division using integers. Here is a modified method that could compute the number of final zeros in n ! for any number up to 1000!. Here are selected results: FZ(100) = 24, FZ(200) = 49, FZ(1000) = 249 Do you notice a pattern? In class we noticed that an approximate answer can be obtained by noting that the number of zeros is strictly less that n /4. In java we can implement this quick rule as: int quickZeros = (n-1)/4; The quick rule follows simply by removing the floor function and using the formula for a geometric series. FZ ( n ) = n 5 k ! " ! # $ # k = 1 % & < n 5 k k = 1 % & = n 1 5 k – 1 k = 0 % & ( ) * + , - = n 1 1 .
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern