sweet1cris

Untitled

Feb 9th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1.  
  2. public class Solution {
  3.     /*
  4.      * @param A: the given number
  5.      * @param B: another number
  6.      * @return: the last digit of B! / A!
  7.      */
  8.     public int computeLastDigit(long A, long B) {
  9.         if(A == B) return 1;
  10.         long left = A+1;
  11.         long right = B;
  12.         int prod = 1;
  13.         for(long i=left;i<=right;i++){
  14.             int lastDigit = (int)i%10;
  15.             prod = (prod * lastDigit)%10;
  16.             if(prod == 0) return 0;
  17.         }
  18.         return prod;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment