# UVa 10515

## Summary

In an expression${\displaystyle m^{n}}$ find the last digit of the number.

## Explanation

• 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
```

## Input

```2 2
2 5
2341423412 321423412342314124324234213421341324321
1232334445 13124123123123123123123123530930900480984530
0 0
```

```4
2
2
5
```