阶乘除法的最后一位数

http://www.lintcode.com/zh-cn/problem/last-digit-by-factorial-divide/

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) {
        // write your code here
        int res = 1;
        for (long i = A + 1; i <= B; i++) {
            int temp = (int) (i % 10);
            if (temp == 0) {
                return 0;
            }
            res *= temp;
            res %= 10;
        }
        return res;
    }
}

你可能感兴趣的:(阶乘除法的最后一位数)