CodeForces 373B Making Sequences is Fun

來源:互聯網
上載者:User

標籤:

Making Sequences is FunTime Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64uSubmit 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) = 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(n)·k 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\n",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             else45             {46                 ww=ww-oo*mm;47             }48             if(mm==0)49                 break;50             //printf("%I64d %I64d %I64d",ww,);51         }52         printf("%I64d\n",n);53     }54     return 0;55 }
View Code

 

CodeForces 373B Making Sequences is Fun

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.