CodeForces 373B

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) = 3,S(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 n to 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 %I64dspecifier.

Output

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

题意是你需要输入一个总的的金钱W,一个起始的数据M,和没构造一个数字需要的金钱K,然后问你从起始数据开始用W可以构造出多少数据。S【X】表示数据X的位数,构造一个数据需要K*S【X】,直接暴力肯定是不行的,可以发现,构造同样多位数的数据所需要的金钱是一样的,所以一次就计算出一个区间的所需的总金钱。


#include <iostream>

#include<cstdio>
#include<algorithm>
#define ll __int64
using namespace std;
ll f[20];
ll w,m,k,ans;
int main()
{    
    f[1]=1;
    int i;
    for(i=2;i<=19;i++) f[i]=f[i-1]*10;                                  // 用数组保存每个几位数中最小的一个数(如:最小的2位数是10)
    while(cin>>w>>m>>k)
    {
        ans=0;
        w/=k;                                                                     //首先算出一共可以构造多少个数字
        for(i=1;i<17;i++)
                if(f[i]>m)
                    break;
        while(w>0)
        {
            if(w>=(f[i]-m)*(i-1))
            {
                ans+=(f[i]-m);
                w-=(f[i]-m)*(i-1);
                m=f[i];
            }
            else
            {
                ans+=w/(i-1);
                w=0;
            }
            m=f[i];
            i++;
        }
       cout<<ans<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值