B - 家


B - 
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

We'll define S(n) for positive integer n as follows: the number of the n's digits in the decimal base. For example, S(893) = 3S(114514) = 6.

You want to make a consecutive integer sequence starting from number m (m, m + 1, ...). But you need to pay S(nk to add the number nto the sequence.

You can spend a cost up to w, and you want to make the sequence as long as possible. Write a program that tells sequence's maximum length.

Input

The first line contains three integers w (1 ≤ w ≤ 1016), m (1 ≤ m ≤ 1016), k (1 ≤ k ≤ 109).

Please, do not write the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cincout streams or the %I64d specifier.

Output

The first line should contain a single integer — the answer to the problem.

Sample Input

Input
9 1 1
Output
9
Input
77 7 7
Output
7
Input
114 5 14
Output
6
Input
1 1 2
Output
0

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;



char bb[100];
__int64 ss(__int64 tmp)
{
 __int64 i,times=0;
	for (;;)
	{
	 tmp=tmp/10;

	 if (tmp)
	 {
		 times++;
	 }
	 else
	 {
		 break;
	 }
	}
	times++;



	return times;
}

int main()
{
	
	__int64 w,m,k;
	
	scanf("%I64d%I64d%I64d",&w,&m,&k);
 	w=w/k;                  //防止溢出,不用也行此题
	__int64 len=0,cost=0;
	__int64 i;
	for (i=m;;i++)
	{ 
		__int64 tmpp=ss(i); 
              //、、、、、、、、、、、、、、、、、、、、、、、此处为关键一,缝十进位,减少计算量,一开始也想到了
 if (cost+( pow((double)10,(int)tmpp)-i)*(tmpp)<=w)
		{
			cost+=( pow((double)10,(int)tmpp)-i)*(tmpp) ;
				len+= pow((double)10,(int)tmpp)-i;
					i+=( pow((double)10,(int)tmpp)-i)-1;
	
			continue;
		}
              //、、、、、、、、、、、、、、、、、、、、、、、

len+=(w-cost)/tmpp; 此处为关键二 ,当最后一位不能进十的时候,误以为一个一个加上去就好了。然后当w足够大k足够小的时候,这个计算量非常大,因此 需要  
 break;   }printf("%I64d\n",len);return 0;} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值