Description

 Problem B.Last Digit 

Background

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

Input file consists of several Ns, each N a line. It is ended with N=0.

Output

For each N give a line containing only one digit, which is the lastdigit of S.

Sample Input

1

2

3

0

Sample Output

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的更多相关文章

  1. 10162 - Last Digit (数论+周期规律)

    UVA 10162 - Last Digit 题目链接 题意:求S=(11+22+...NN)%10 思路:打出0-9的每一个周期,发现周期为1或2或4.所以S是以20一个周期,打出表后发现20为4. ...

  2. 【UVA 1583】Digit Generator

    题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...

  3. 【例题3-5 UVA - 1583】Digit Generator

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] for (int i = 1;i <= n;i++) { 算出i是哪一个的生成元. 假设是y. 则ans[y] = min(a ...

  4. UVa 1225 Digit Counting --- 水题

    UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...

  5. UVa 1583 Digit Generator --- 水题+打表

    UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...

  6. Digit Counting UVA - 1225

    ​ Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequ ...

  7. 数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)

    思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. ...

  8. 生成元(Digit Generator ,ACM/ICPC Seoul 2005 ,UVa 1583)

    生成元:如果 x 加上 x 各个数字之和得到y,则说x是y的生成元. n(1<=n<=100000),求最小生成元,无解输出0. 例如:n=216 , 解是:198 198+1+9+8=2 ...

  9. UVa 1225 Digit Counting

    题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...

随机推荐

  1. [BZOJ4560][JLOI2016]字符串覆盖(贪心+DP)

    先用KMP求出所有可以放的位置,然后两个值分别处理. 最大值: 贪心,4!枚举放的先后位置顺序,2^3枚举相邻两个串是否有交. 若有交,则后一个的起始位置一定是离前一个的结束位置最近的位置,无交也一样 ...

  2. Ubuntu 12.04下spark1.0.0 集群搭建(原创)

    spark1.0.0新版本的于2014-05-30正式发布啦,新的spark版本带来了很多新的特性,提供了更好的API支持,spark1.0.0增加了Spark SQL组件,增强了标准库(ML.str ...

  3. python使用UnboundMethodType修改类方法

    from types import UnboundMethodType class class1(object): def fun1(self): print 'fun1' oldfun1 = cla ...

  4. noip200705统计数字

    试题描述: 某次科研调查时得到了n个自然数,每个数均不超过1500000000(1.5*109).已知不相同的数不超过10000个,现在需要统计这些自然数各自出现的次数,并按照自然数从小到大的顺序输出 ...

  5. Theme.AppCompat无全屏主题解决办法

    V7包中的Theme.AppCompat主题系列中并没有全屏样式,这个是为什么,只有作者知道…… 解决办法: 自定义主题 <style name="Theme.AppCompat.Li ...

  6. git中:关于origin和master

    git的服务器端(remote)端包含多个repository,每个repository可以理解为一个项目.而每个repository下有多个branch."origin"就是指向 ...

  7. extjs grid数据改变后刷新的实现

    做了一个编辑extjs grid记录的窗体,但更改数据后,怎么重新刷新grid让数据显示呢? 做了半天的尝试,其实到最后只需一句话,faint:-) this.store.reload(); 不用加任 ...

  8. Windows下配置Git服务器和客户端

    http://www.cnblogs.com/lwme/archive/2012/12/25/configuring-git-server-and-client-on-windows.html] 选择 ...

  9. HDU 1159 &amp;&amp; POJ 1458

    最长公共子序列.状态转移方程见代码. #include <iostream> #include <cstdio> #include <cstring> using ...

  10. .NET Versioning and Multi-Targeting - .NET 4.5 is an in-place upgrade to .NET 4.0

    Say what you will about the past ridiculousness of .NET Framework versioning, since the confusion of ...