2905 Number Sequence

Number Sequence

时间限制(普通/Java):1000MS/3000MS     运行内存限制:65536KByte
总提交: 6            测试通过: 2

描述

This is simple a number sequence problem. In this problem a positive integer n will repeated n times. And number will start with 1 and continue to infinite.

For example: if n is 11 then 11 will repeated 11 times.(11 11 11 11 11 11 11 11 11 11 11).

In this problem you are expected to write a program that take a positive number p and display the digit of position p.

   p|    1   2   3   4   5  6   7   8   9   10   11   12   13   14   15   16   17   18   19   20    21 
d(p)|  1    2   2   3   3  3   4   4   4    4     5     5    5       5    5     6     6     6     6     6     6

 

输入

The input may contain multiple test cases. Each test case occupies a separate line and contains an integer n (1 ≤ n ≤ 199000000 ). The input terminates by end of file marker.

 

输出

For each test case in the input output the digit of n position on a separate line.

样例输入

 

1
11
14
19
21
22
46
47
48
49

 

样例输出

 

1
5
5
6
6
7
1
0
1
0
分析:先说下题目大概意思。
p| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 .....46 47 48 49
d(p)| 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 ...... 1     0  1     0
好了  看了这个估计知道了。
进入正题。题目要求你输入p,表示的第p个位置的数字,注意不是数,是数字。如果是10的话第一个数字是1.
p的话表示第p个数字。
先我们推测下,199000000,最大的数是多少或者说最大的位数。
1*2+1*3+1*4+。。。。4*9999+。。。 前面的数字表示位数,后面的数字表示当前数。
他们的和就是数字的位置了。我测试了下他的和大于199000000的最小值是4位数的。那么最大的数也才9999,那么好,空间已经比较小了,我们可以开始做了。
我的思路是保存到数组b[]  小标表示数,值表示位置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

helihui123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值