Friday, January 24, 2014

SPOJ 3442. The last Digit

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

For solving this task we need to notice one thing . Have a look at the 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


The table above shows you teh last digits of numbers from 1 to 9 .For every number the last digit will be repeated after the 4 th power at best. So you just need to check the remainder when b divided on 4 and output the answer according to this table. 



       DOWNLOAD THE FULL SOURCE CODE

No comments:

Post a Comment