Submit | All submissions | Best solutions | Back to list |
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
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 |
hide comments
|
||||||||||||||
2012-10-30 17:41:01 No_words
700B ?? is it correct ? :O |
||||||||||||||
2012-10-07 20:56:36 Rajagopal
what data structure can be used if we need to program in c/c++. |
||||||||||||||
2012-09-15 02:14:48 Rodrigo Salazar
If you're having trouble understanding or solving this problem, try checking out: http://www.swageroo.com/wordpress/spoj-problem-3442-the-last-digit-lastdig/ |
||||||||||||||
2012-09-14 20:16:03 Abhimanyu
wasted couple of hours taking array of 10 ... while it should be 11 ... wondering why it still showed the right answer on my machine even for largest data ... stil got AC .. silly mistakes !! :) Last edit: 2012-09-14 20:19:41 |
||||||||||||||
2012-09-14 17:36:48 Jose Daniel RodrÃguez Morales
Source Limit should be enough PS: the data tests were fixed |
||||||||||||||
2012-09-14 17:36:48 Prakash Murthy
My original code broke down when a=20 & b=214,748,3000 Found a better algorithm, and got accepted. ;-) In the second attempt, had forgotten the case of any number raised to 0 is 1. Last edit: 2012-08-13 17:06:10 |
||||||||||||||
2012-09-14 17:36:48 gourav
what is tricky case ? |
||||||||||||||
2012-09-14 17:36:48 InVoKe[R]
NZEC (non-zero exit code) - this message means that the program exited returning a value different from 0 to the shell. For languages such as C, this probably means you forgot to add "return 0" at the end of the program. For interpreted languages (including JAVA) NZEC will usually mean that your program either crashed or raised an uncaught exception. Last edit: 2012-08-03 07:52:02 |
||||||||||||||
2012-09-14 17:36:48 007: Name stolen
can anyone tell me why my code is giving NZEC id 7393791 |
||||||||||||||
2012-09-14 17:36:48 Preetam Shivaram
@Jose Daniel RodrÃguez Morales-in which case my code gives error..code id is 7278511 |