Making sequences is funTime
limit:2000MS
Memory Limit:262144KB
64bit IO Format:%i64d &%i6 4u SubmitStatusPracticecodeforces 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 ≤10), m (1≤ m ≤10), k (1≤ k ≤109).
Please, don't 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 LongSS (Long Longa)4 {5 Long Longx=0;6 while(a>0)7 {8a=a/Ten;9X + +;Ten //printf ("%i64d\n", a); One } A returnx; - } - the Long LongNumLong Longx) - { - Long Longi,y=1; - for(i=1; i<=x;i++) +y=y*Ten; - returny; + } A intMain () at { - Long Longw,m,k; - inti,j; - while(SCANF ("%i64d%i64d%i64d", &w,&m,&k)! =EOF) - { - Long Longn=0, nu,ww,mm; in Long Longoo=SS (m); -nu=num (oo); toww=w/K; + while(ww>0) - { themm=ww/Oo; *n=n+mm; $ if(n>=nu-m)Panax Notoginseng { -mm=mm-(n-nu+m); then=nu-m; +ww=ww-oo*mm; Aoo++; thenu=num (oo); + } - Else $ { $ww=ww-oo*mm; - } - if(mm==0) the Break; - //printf ("%i64d%i64d%i64d", WW,);Wuyi } theprintf"%i64d\n", n); - } Wu return 0; -}
View Code
Codeforces 373B Making sequences is fun