标签:des style http color os io strong for
Description
Problem B.Last Digit |
Give you a integer number N (1<=n<=2*10100). Pleasecompute
S=11+22+33+…+NN
Give the last digit of S to me.
Input file consists of several Ns, each N a line. It is ended with N=0.
For each N give a line containing only one digit, which is the lastdigit of S.
1
2
3
0
1
5
2
题意:求S的个位是多少
思路:看到这么大的数,先打个表试试,发现每20项是个小循环,每100项是个大循环,直接记录100项的结果计算
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; const int maxn = 300; int num[maxn]; char str[maxn]; int main() { int ans = 0; for (int i = 1; i <= 200; i++) { int tmp = 1; for (int j = 1; j <= i; j++) tmp = tmp * i % 10; ans = (ans + tmp) % 10; num[i] = ans; } while (scanf("%s", str) != EOF && str[0] != '0') { int len = strlen(str); int cnt = 0; for (int i = 0; i < len; i++) cnt = (cnt * 10 + str[i] - '0') % 100; if (!cnt) cnt = 100; printf("%d\n", num[cnt]); } return 0; }
UVA - 10162 Last Digit,布布扣,bubuko.com
标签:des style http color os io strong for
原文地址:http://blog.csdn.net/u011345136/article/details/38460239