Submit | All submissions | Best solutions | Back to list |
LASTDIG2 - The last digit re-visited |
Pappu 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 two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Pappu with his problem. You are given two integer numbers: the base a (number of digits d, such that 1 <= d <= 1000) and the index b (0 <= b <= 922*10^15). You have to find the last digit of a^b.
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: 3 3 10 6 2 150 53 Output: 9 6 0
Source limit is 700 Bytes.
Added by: | Hari |
Date: | 2009-12-27 |
Time limit: | 1s |
Source limit: | 700B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS OBJC PERL6 SQLITE VB.NET |
Resource: | harrydcoder |
hide comments
|
|||||||||||
2020-07-04 09:11:30
both 1 and 0 are accepted for case 0 0 |
|||||||||||
2020-03-25 15:27:21
By 700 bytes they mean size of your code, that is total characters in your code. And make sure your code is less than 700 characters because editor likes to add extra bytes for some reason. See - "http://discuss.spoj.com/t/your-solution-is-too-long-for-this-problem-fctrl2/2748". |
|||||||||||
2020-01-24 14:24:39
use python pow(a,b,10) : pow function calculates a**b and then does %10 . Time limit won't be exceeded if used |
|||||||||||
2019-07-29 19:36:39
just use python for this |
|||||||||||
2019-05-23 21:58:17
one liner in python print(pow(a,b,10)) |
|||||||||||
2018-06-28 10:26:53
very easy ac at last |
|||||||||||
2018-06-13 23:24:11
Test cases are very weak: 1 4 8 Even if your solution outputs "1", you will still get AC (assuming you handled the edge case) |
|||||||||||
2018-06-12 15:04:16
@srijan123j it will be 0 this costed me 2 WA |
|||||||||||
2018-05-03 08:07:40
source limit 700 bytes i am not able to space optimize my code ! |
|||||||||||
2018-02-21 20:08:06
AC in One GO !!! |