Find the last digit when factorial of A divides factorial of B
Submissions: 1228   Accuracy:

29.19%

  Difficulty: Medium   Marks: 4

Given two numbers A and B. The task is to compute the last digit of the resulting F, where F= B! / A! .

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains two number A and B as input.

Output:
For each test case, print last digit of B! / A! (B factorial/ A factorial).

Constraints:
1<=T<=100
1<=A<=B<=1018

Example:
Input:
2

2 4
107 109

Output:
2
2

Explanation:

Input : A = 2, B = 4
Output : 2
Explanation : A! = 2 and B! = 24. 
F = 24/2 = 12 --> last digit = 2

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Arun Tyagi
Author: arun03


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.