Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution {
- /*
- * @param A: the given number
- * @param B: another number
- * @return: the last digit of B! / A!
- */
- public int computeLastDigit(long A, long B) {
- if(A == B) return 1;
- long left = A+1;
- long right = B;
- int prod = 1;
- for(long i=left;i<=right;i++){
- int lastDigit = (int)i%10;
- prod = (prod * lastDigit)%10;
- if(prod == 0) return 0;
- }
- return prod;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment