Friday, January 24, 2014

SPOJ 5699. The last digit re-visited

http://www.spoj.com/problems/LASTDIG2/

This probelm is similar to the probelm The Last Digit (LASTDIG), here I wrote about it as well.
 For solving this task you need to know one thing, Have a look at teh table below

Number
1 power
2 power
3 power
4 power
1
1
1
1
1
2
2
4
8
6
3
3
9
7
1
4
4
6
4
6
5
5
5
5
5
6
6
6
6
6
7
7
9
3
1
8
8
4
2
6
9
9
1
9
1


As you can see, teh last digit of every number's power will be repeated every 4 powers at best. You just need to take the remainder of b divided on 4 and output the answer according to this table. 



       DOWNLOAD THE FULL SOURCE CODE

No comments:

Post a Comment