Question: We know S = Σ (I ^ I) Where (1 <= I <= N) calculates the number of the last digit of S.
Analysis: number theory. Find the rule. If I = 10 * A + B, then I ^ I = (10 * A + B) ^ (10 * A + B), which includes:
Note f (I) = (I ^ I) % 10 = (10 * A + B) ^ (10 * A + B) % 10 = B ^ (10 * A + B) {binary theorem}
Use f (I) to find the rule:
F (10 * k + 0) = 0;
F (10 * k + 1) = 1;
F (10 * k + 2) = 4,6; {F (2) = 4, F (12) = 6, F (22) = 4, F (32) = 6 ,...}
F (10 * k + 3) = 7,3; {same as above}
F (10 * k + 4) = 6;
F (10 * k + 5) = 5;
F (10 * k + 6) = 6;
F (10 * k + 7) = 3,7; {same as above}
F (10 * k + 8) = 6, 4; {same as above}
F (10 * k + 3) = 9;
Therefore, we can conclude that the cycle is a multiple of 20:
,
,
,
,
6, 7,
Because the number of tails after 20 cycles is 4 more than the previous cycle, the cycle is 100;
Take out the last two digits (% 100) of the input number and output (Value % 20 + 4 * value/20) % 10.
Note: (⊙ _ ⊙)
#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;int maps[20] = {0,1,5,2,8,3,9,2,8,7,7,8,4,7,3,8,4,1,5,4};int main(){string str;while ( cin >> str ) {int len = str.length();if ( len == 1 && str[0] == '0' )break;int value = str[len-1]-'0';if ( len > 1 )value += (str[len-2]-'0')*10;cout << (maps[value%20]+value/20*4)%10 << endl;}return 0;}