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. BZOJ1552/3506 [Cerc2007]robotic sort

    Splay 与之前不同的是如果你仅仅是翻转左右区间的话可以在find里面做因为对他有影响的子树在做之前一定在他的上面从上到下搜索的过程可以把rever做了. 但这道题要求我们输出转换之前的,因此不能保 ...

  2. java高并发程序设计模式-并发级别:阻塞、无障碍、无锁、无等待【转载】

    一般认为并发可以分为阻塞与非阻塞,对于非阻塞可以进一步细分为无障碍.无锁.无等待,下面就对这几个并发级别,作一些简单的介绍. 1.阻塞 阻塞是指一个线程进入临界区后,其它线程就必须在临界区外等待,待进 ...

  3. bzoj 2179: FFT快速傅立叶 -- FFT

    2179: FFT快速傅立叶 Time Limit: 10 Sec  Memory Limit: 259 MB Description 给出两个n位10进制整数x和y,你需要计算x*y. Input ...

  4. nginx 访问第三方服务(1)

    nginx提供了两种全异步方式来与第三方服务通信,分别是upstream和subrequest. upstream:nginx为代理服务器,作消息透传.将第三方服务的内容原封不动的返回给用户. sub ...

  5. java_es

    在查询时过滤掉指定的"_id"的数据 GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();// 对 ...

  6. HDU 5673 Robot 数学

    Robot 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 Description There is a robot on the origi ...

  7. fork新建进程——父进程等待子进程结束

    #include <sys/types.h>#include<sys/wait.h>#include<unistd.h>#include<stdio.h> ...

  8. centos安装单机zookeeper

    1.下载zookeeper版本 wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz ...

  9. BFC与hasLayout

    BFC与hasLayout都是CSS布局上的概念. 几个月前在微博上才了解什么是BFC,算是对布局有点初步的了解. hasLayout则是IE6.7产生许多bug的根源. 一.BFC Floats, ...

  10. Android 动画——Layout Animations布局动画

    Layout Animations主要使用LayoutTransition为布局的容器设置动画,当容器中的视图层次发生变化时存在过渡的动画效果. LayoutTransition This class ...