Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1103
1. First look at the rule of a single number:
0^n%10:0
1^n%10:1
2^n%10:2,4,8,6
3^n%10:3,9,7,1
4^n%10:4,6
5^n%10:5
6^n%10:6
7^n%10:7,9,3,1
8^n%10:8,4,2,6
9^n%10:9,1
2. Because the maximum cycle length is 4, we can see that the i^i%10 and i^ (i+20)%10 are the same, that is to say, the i^i%10 cycle is 20
and (1^1+......+20^20)%10=4,
So (1^1+......+40^40)%10=8,
(1^1+......+60^60)%10=2,
(1^1+......+80^80)%10=6,
(1^1+......+100^100)%10=0,
So it appears that S (N)%10=s (n%100)%10
So consider the latter two digits of N.
3. To simplify operations, further analysis is possible:
It may be calculated (1^1+......+10^10)%10=7, so (11^11+......+20^20)%10=7 (4-7+10=7 above), so that every 10 number and modulo 10 7,
Then we calculate the single digit of s (1) ~s (10) and the Single-digit a[i of [s (a)-s (]~[s)-S (10)],
Remember b=n%100, then ans= (b/10*7+a[b%20])%10
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Complete code:
01./*0.015s*/
.
#include <bits/stdc++.h>
04.using namespace std;
05.const int a[20] = {0, 1, 5, 2, 8, 3, 9, 2, 8, 7, 0, 1, 7, 0, 6, 1, 7, 4, 8, 7}; S (N)%10,0<=n<=19
.
07.char s[105];
09.int Main ()
10.{ int Len, b, C; while (gets (s), s[0]!= ' 0 ')
. { len = strlen (s); if (len = = 1) b = s[0] &; Else B = atoi (s + len-2); printf ("%d\n", (B/10 * 7 + a[b%));
. return 0;
20.}