B - 家

来源:互联网 发布:好看编程图片 编辑:程序博客网 时间:2024/04/28 05:57


B - 
Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit Status Practice CodeForces 373B

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;} 


0 0