Making Sequences is Fun

Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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(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
 #include <stdio.h>
#include <string.h>
long long SS(long long a)
{
long long x=;
while(a>)
{
a=a/;
x++;
//printf("%I64d\n",a);
}
return x;
} long long num(long long x)
{
long long i,y=;
for(i=;i<=x;i++)
y=y*;
return y;
}
int main()
{
long long w,m,k;
int i,j;
while(scanf("%I64d %I64d %I64d",&w,&m,&k)!=EOF)
{
long long n=,nu,ww,mm;
long long oo=SS(m);
nu=num(oo);
ww=w/k;
while(ww>)
{
mm=ww/oo;
n=n+mm;
if(n>=nu-m)
{
mm=mm-(n-nu+m);
n=nu-m;
ww=ww-oo*mm;
oo++;
nu=num(oo);
}
else
{
ww=ww-oo*mm;
}
if(mm==)
break;
//printf("%I64d %I64d %I64d",ww,);
}
printf("%I64d\n",n);
}
return ;
}

CodeForces 373B Making Sequences is Fun的更多相关文章

  1. codeforces B. Making Sequences is Fun 解题报告

    题目链接:http://codeforces.com/problemset/problem/373/B 题目意思:给出w,m和k,需要找出从m开始,可以有多少个连续的数(m+1,m+2,...)(在添 ...

  2. Codeforces 900D Unusual Sequences 容斥原理

    题目链接:900D  Unusual Sequences 题意: 给出两个数N,M.让你求数列(和为M,gcd为N)的个数. 题解: 首先,比较容易发现的是M%N如果不为零,那么一定不能构成这样的序列 ...

  3. CodeForces 900D Unusual Sequences

    题目链接: https://codeforces.com/contest/900/problem/D 题意 假设有distinct 正整数序列{a1,a2,,,an},满足gcd(a1, a2, .. ...

  4. Codeforces 264B Good Sequences(DP+素数筛)

    题目链接:http://codeforces.com/problemset/problem/264/B 题目大意:给出n个单调递增的数,让你找出最长的好序列,好序列是一种单调递增的并且相邻元素的最大公 ...

  5. Codeforces 900D Unusual Sequences:记忆化搜索

    题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...

  6. CodeForces 1166D Cute Sequences

    题目链接:http://codeforces.com/problemset/problem/1166/D 题目大意 给定序列的第一个元素 a 和最后一个元素 b 还有一个限制 m,请构造一个序列,序列 ...

  7. Codeforces Jzzhu and Sequences(圆形截面)

    # include <stdio.h> int f[10]; int main() { int x,y,n,j; while(~scanf("%d%d%d",& ...

  8. Codeforces Round #167 (Div. 2) D. Dima and Two Sequences 排列组合

    题目链接: http://codeforces.com/problemset/problem/272/D D. Dima and Two Sequences time limit per test2 ...

  9. codeforces#FF DIV2C题DZY Loves Sequences(DP)

    题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...

随机推荐

  1. zw版【转发·台湾nvp系列Delphi例程】HALCON InpaintingCt2

    zw版[转发·台湾nvp系列Delphi例程]HALCON InpaintingCt2 unit Unit1;interfaceuses Windows, Messages, SysUtils, Va ...

  2. OpenStack 的防火墙规则流程

    Contents [hide] 1 发现的问题 2 解决过程 3 删除临时错误数据 4 其实前面的解决办法是错的 发现的问题 3台虚拟机在同一宿主机,防火墙配置都一样,但是他们的网络表现不一致,有的能 ...

  3. SQL SERVER2012秘钥

    来自网络: MICROSOFT SQL SERVER 2012 DEVELOPER 版(开发版)序列号:YQWTX-G8T4R-QW4XX-BVH62-GP68YMICROSOFT SQL SERVE ...

  4. drupal 做301跳转(删除url里的www), 关键代码 可用到任何网站

    //hook_init(); function ex_init(){ //删除 url 前面的 www if (substr($_SERVER['HTTP_HOST'],0,3) == 'www'){ ...

  5. Java ActiveMQ 讲解(一)理解JMS 和 ActiveMQ基本使用(转)

    转自:http://www.cnblogs.com/luochengqiuse/p/4678020.html?utm_source=tuicool&utm_medium=referral 最近 ...

  6. 为 Macbook 安装 wget 命令

    没想到装个这个命令那么麻烦, 还要装 xcode?..... 好吧,按步骤来成功装上 http://www.arefly.com/mac-wget/ 其實Mac也自帶了一個Curl同樣也可以下載網頁, ...

  7. Linux 进程状态【转】

    转自:http://www.cnblogs.com/itech/p/3208261.html 来自: http://blog.csdn.net/tianlesoftware/article/detai ...

  8. jQuery的Ajax的跨域请求

    今天碰到一个Ajax跨域请求的问题,我把源码down下来,然后在服务器端写了一个http请求的代理(因为服务器端是不存在跨域问题的),说白了就是用BufferedReader写了个IO流,然后读取到目 ...

  9. 对于改善 MySQL 数据装载操作有效率的方法是怎样

    多时候关心的是优化SELECT 查询,因为它们是最常用的查询,而且确定怎样优化它们并不总是直截了当.相对来说,将数据装入数据库是直截了当的.然而,也存在可用来改善数据装载操作效率的策略,其基本原理如下 ...

  10. 标准类型String(学习中)

    1.读取string对象 #include<iostream> #include<cstring> using namespace std; int main() { stri ...