729. Last Digit By Factorial Divide
Description 中文 English We are given two numbers A and B such that B >= A . We need to compute the last digit of this resulting F such that F = B! / A! where 1 <= A, B <= 10^18 (A and B are very large) Have you met this question in a real interview? Yes Problem Correction Example Given A = 2, B = 4, return 2 A! = 2 and B! = 24, F = 24 / 2 = 12 --> last digit = 2 Given A = 107, B = 109, return 2 只看个位数就好了。有意思 int computeLastDigit ( long long A, long long B) { // write your code here int res = 1 ; for ( long long i = A + 1 ; i <= B; i++){ res *= (i % 10 ); res %= 10 ; if (res == 0 ){ return 0 ; } } return res; }