UVA - 10162 Last Digit
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的更多相关文章
- 10162 - Last Digit (数论+周期规律)
UVA 10162 - Last Digit 题目链接 题意:求S=(11+22+...NN)%10 思路:打出0-9的每一个周期,发现周期为1或2或4.所以S是以20一个周期,打出表后发现20为4. ...
- 【UVA 1583】Digit Generator
题 题意 a加上 a的各位数=b,则b是a的digitSum,a是b的generator,现在给你digitSum,让你求它的最小的generator. 分析 一种方法是: 预处理打表,也就是把1到1 ...
- 【例题3-5 UVA - 1583】Digit Generator
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] for (int i = 1;i <= n;i++) { 算出i是哪一个的生成元. 假设是y. 则ans[y] = min(a ...
- UVa 1225 Digit Counting --- 水题
UVa 1225 题目大意:把前n(n<=10000)个整数顺次写在一起,12345678910111213...,数一数0-9各出现多少字 解题思路:用一个cnt数组记录0-9这10个数字出现 ...
- UVa 1583 Digit Generator --- 水题+打表
UVa 1583 题目大意:如果x加上x的各个数字之和得到y,那么称x是y的生成元. 给定数字n,求它的最小生成元 解题思路:可以利用打表的方法,提前计算出以i为生成元的数,设为d,并保存在a[d]中 ...
- Digit Counting UVA - 1225
Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequ ...
- 数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)
思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. ...
- 生成元(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 ...
- UVa 1225 Digit Counting
题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...
随机推荐
- 【BZOJ 2039】 2039: [2009国家集训队]employ人员雇佣 (最小割)
2039: [2009国家集训队]employ人员雇佣 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1511 Solved: 728 Descri ...
- codevs 1102 采药 2005年NOIP全国联赛普及组
1102 采药 2005年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB gold 题目描述 Description 辰辰是个天资聪颖的孩子,他的梦想是成为世界上最 ...
- NOI1999 JZYZOJ1289 棋盘分割 dp 方差的数学结论
http://172.20.6.3/Problem_Show.asp?id=1289 除了下标一坨一坨屎一样挺恶心其他都还挺容易的dp,这道题才发现scanf保留小数位是四舍五入的,惊了. f[k][ ...
- poj 1485 dp
转自:http://www.cnblogs.com/kuangbin/archive/2011/11/12/2246407.html [题目大意] 一条公路上有n个旅馆,选出其中k个设置仓库,一个仓库 ...
- Unity 播放音频文件
Unity 播放音频文件参考代码: public void Play(string strSoundName, float autoDestroyTime = 0f, bool bLoop = fal ...
- Swift 闭包反向传值
Swift中闭包反向传值 1.第二控制器申明一个闭包类型 typealias BackBlock = (String) -> Void 2.第二控制器定义一个变量 var BackBlockCl ...
- Java中文件与字节数组转换
注:来源于JavaEye 文件转化为字节数组: http://www.javaeye.com/topic/304980 /** * 文件转化为字节数组 * * @param file * @retur ...
- TCP/IP协议栈与数据报封装 (802.3 Ethernet 以太网 802.11 WLAN 无线网 )
http://blog.csdn.net/jnu_simba/article/details/8957242 一.ISO/OSI参考模型 OSI(open system interconnection ...
- 让linux history命令显示命令的运行时间、在哪个机器运行的这个命令
1.在/etc/profile的最后加入例如以下部分: USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g ...
- DELPHI纤程的演示
DELPHI纤程的演示 DELPHI7编译运行通过. 纤程实现单元: unit FiberFun; //Fiber(纤程测试Demo)//2018/04/11//QQ: 287413288 //参考 ...