LASTDIG - The last digit
Nestor was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives him two numbers a and b. The problem consist of finding the last digit of the potency of base a and index b. Help Nestor with his problem. You are given two integer numbers: the base a (0 <= a <= 20) and the index b (0 <= b <= 2,147,483,000), a and b both are not 0. You have to find the last digit of ab.
Input
The first line of input contains an integer t, the number of test cases (t <= 30). t test cases follow. For each test case will appear a and b separated by space.
Output
For each test case output an integer per line representing the result.
Example
Input: 2 3 10 6 2
Output: 9 6
hide comments
thirupathireddy:
2015-09-03 14:40:51
this is not good mentioning that both a and b not zero.............
|
|
Mahesh Chaurasia:
2015-08-03 05:27:31
Please consider case a==0 and b==0; Considering them not together. |
|
rahulwahi:
2015-07-25 16:52:31
@avid coder
|
|
Avinash Bansal:
2015-07-19 20:05:05
check the test case when index=0,
|
|
einsdurchnull:
2015-07-18 08:47:13
I got TLE with Modular Exponentiation in C :\ |
|
Avinash Kumar:
2015-07-18 08:16:33
if you get 700 bytes limit error, remove all spaces. while solving just remember 1,4,4,2,1 :] |
|
surya97:
2015-07-14 23:16:14
removed extra space and thus got accepted.
|
|
Shivam Singh:
2015-07-12 13:28:00
you only need the last digit of a to find the last digit of any of its powers.
|
|
hacker_1995:
2015-07-04 09:40:06
YOU CAN FIND THE C++ SOLUTION HERE IF YOU CAN'T SOLVE IT
|
|
darthmelonder:
2015-06-20 20:47:26
b=0 case is included despite the contradicting constraints... -_- Last edit: 2015-06-20 20:48:54 |
Added by: | Jose Daniel Rodriguez Morales |
Date: | 2008-12-01 |
Time limit: | 1s |
Source limit: | 700B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: GOSU |
Resource: | Own |