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 2428 JZYZOJ1533 : [HAOI2006]均分数据 模拟退火 随机化
http://www.lydsy.com/JudgeOnline/problem.php?id=2428 http://172.20.6.3/Problem_Show.asp?id=1533 http ...
- CodeForces - 1017D The Wu
题面在这里! 比较显而易见的暴力,O(2^(2n) + 2^n * 100) 就可以直接做了 #include<bits/stdc++.h> #define ll long long us ...
- bzoj 1231: [Usaco2008 Nov]mixup2 混乱的奶牛 -- 状压DP
1231: [Usaco2008 Nov]mixup2 混乱的奶牛 Time Limit: 10 Sec Memory Limit: 162 MB Description 混乱的奶牛 [Don Pi ...
- Nginx -- nginx.conf 配置文件详讲
Nginx服务器配置,nginx.conf文件代码详讲,结合不同楼主的博文得到: #关掉访问日志可以优化服务器 #定义Nginx运行的用户和用户组 #user nobody; #nginx进程数 #如 ...
- ThinkPHP -- 基础入门
ThinkPHP文件结构说明: |——ThinkPHP.php 框架入口文件 |——Common 框架公共文件目录 |——Conf ...
- PAT甲级1018. Public Bike Management
PAT甲级1018. Public Bike Management 题意: 杭州市有公共自行车服务,为世界各地的游客提供了极大的便利.人们可以在任何一个车站租一辆自行车,并将其送回城市的任何其他车站. ...
- Linux知识(4)----文件系统结构
Ubantu 14.04的文件系统结构如下图所示: 参考资料: 1.http://www.cnblogs.com/wen858636827/archive/2012/12/26/2834373.htm ...
- 为什么要使用netty
选择Netty的理由在开始本节之前,我先讲一个亲身经历的故事:曾经有两个项目组同时用到了NIO编程技术,一个项目组选择自己开发NIO服务端,直接使用JDK原生的API,结果2个多月过去了,他们的NIO ...
- pom通用依赖
<dependencies><!--common--><dependency><groupId>com.google.guava</groupId ...
- Android中数据存储(三)——SQLite数据库存储数据
当一个应用程序在Android中安装后,我们在使用应用的过程中会产生很多的数据,应用都有自己的数据,那么我们应该如何存储数据呢? 数据存储方式 Android 的数据存储有5种方式: 1. Share ...