• Making Sequences is Fun373B


    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 numbern 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 cin, cout streams or the %I64dspecifier.

    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
     1 #include <stdio.h>
     2 #include <string.h>
     3 long long SS(long long a)
     4 {
     5     long long x=0;
     6     while(a>0)
     7     {
     8         a=a/10;
     9         x++;
    10         //printf("%I64d
    ",a);
    11     }
    12     return x;
    13 }
    14 
    15 long long num(long long x)
    16 {
    17     long long i,y=1;
    18     for(i=1;i<=x;i++)
    19         y=y*10;
    20     return y;
    21 }
    22 int main()
    23 {
    24     long long w,m,k;
    25     int i,j;
    26     while(scanf("%I64d %I64d %I64d",&w,&m,&k)!=EOF)
    27     {
    28         long long n=0,nu,ww,mm;
    29         long long oo=SS(m);
    30         nu=num(oo);
    31         ww=w/k;
    32         while(ww>0)
    33         {
    34             mm=ww/oo;
    35             n=n+mm;
    36             if(n>=nu-m)
    37             {
    38                 mm=mm-(n-nu+m);
    39                 n=nu-m;
    40                 ww=ww-oo*mm;
    41                 oo++;
    42                 nu=num(oo);
    43             }
    44             else
    45             {
    46                 ww=ww-oo*mm;
    47             }
    48             if(mm==0)
    49                 break;
    50             //printf("%I64d %I64d %I64d",ww,);
    51         }
    52         printf("%I64d
    ",n);
    53     }
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    falsk 自定义中间件
    练习题
    4.12 作业题
    测试笔试题2
    测试笔试题
    简答题
    单选题
    普华和诚测试笔试试题
    缺陷报告
    测试用例点
  • 原文地址:https://www.cnblogs.com/cyd308/p/4658557.html
Copyright © 2020-2023  润新知