UVa 10515

From Algorithmist
Jump to navigation Jump to search

10515 - Power et al.[edit]

Summary[edit]

In an expression find the last digit of the number.

Explanation[edit]

  • A bad approach resulting in an overflow would be:
for 1 to n number=(number*m)%10;  
  • Another approach using number theory is find the number of changes in the last digit for m*n.
  • You do not need the entire 10^101 number in order to calculate last digit of m^n.
  • Oddly enough you only need the last digit of the first number and the last two digits of the second number.
  • Just a few hints with the number theory part.
Divisibility:
1: any real number
2: last digit divisible by 2
4: last 2 digits divisible by 4. ie. 32 or 332 or 3333333332

Implementations[edit]

Input[edit]

2 2
2 5
2341423412 321423412342314124324234213421341324321
1232334445 13124123123123123123123123530930900480984530
0 0

Output[edit]

4
2
2
5