CodeForces 373B 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(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
9 1 1
9
77 7 7
7
114 5 14
6
1 1 2
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的更多相关文章
- codeforces B. Making Sequences is Fun 解题报告
题目链接:http://codeforces.com/problemset/problem/373/B 题目意思:给出w,m和k,需要找出从m开始,可以有多少个连续的数(m+1,m+2,...)(在添 ...
- Codeforces 900D Unusual Sequences 容斥原理
题目链接:900D Unusual Sequences 题意: 给出两个数N,M.让你求数列(和为M,gcd为N)的个数. 题解: 首先,比较容易发现的是M%N如果不为零,那么一定不能构成这样的序列 ...
- CodeForces 900D Unusual Sequences
题目链接: https://codeforces.com/contest/900/problem/D 题意 假设有distinct 正整数序列{a1,a2,,,an},满足gcd(a1, a2, .. ...
- Codeforces 264B Good Sequences(DP+素数筛)
题目链接:http://codeforces.com/problemset/problem/264/B 题目大意:给出n个单调递增的数,让你找出最长的好序列,好序列是一种单调递增的并且相邻元素的最大公 ...
- Codeforces 900D Unusual Sequences:记忆化搜索
题目链接:http://codeforces.com/problemset/problem/900/D 题意: 给定x,y,问你有多少个数列a满足gcd(a[i]) = x 且 ∑(a[i]) = y ...
- CodeForces 1166D Cute Sequences
题目链接:http://codeforces.com/problemset/problem/1166/D 题目大意 给定序列的第一个元素 a 和最后一个元素 b 还有一个限制 m,请构造一个序列,序列 ...
- Codeforces Jzzhu and Sequences(圆形截面)
# include <stdio.h> int f[10]; int main() { int x,y,n,j; while(~scanf("%d%d%d",& ...
- 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 ...
- codeforces#FF DIV2C题DZY Loves Sequences(DP)
题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...
随机推荐
- small details
1.操作数据时,一般能入库就入库,或者用xml文件,用文件操作比较复杂
- decimal.tostring()格式
nt/Decimal.ToString 方法 (String, IFormatProvider) decimal value = 16325.62m; string specifier; Cult ...
- ssh-keygen+ssh-copy-id 在linux下实现ssh无密码登录访问(转)
转自:http://blog.csdn.net/pennyliang/article/details/8556662 ssh-keygen+ssh-copy-id 在linux下实现ssh无密码登录访 ...
- html5 图片热点area,map的用法
今天看了一个html5在图片上面创建热点的标签,所谓图片热点就是给你一张图片然后你可以设置点击图片不同的位置进入不同的链接!如果下面是一张图片的话,里面在长方形.圆形.三角形区域都可以进入其他网页! ...
- 去除冗余 – 精简您的CSS样式代码
讲讲常见的一些没有必要使用CSS代码情况,而这些不起作用可以去掉的CSS代码可能是我们经常忽视的.越是对CSS理解不够,越容易出现这些问题. 二.一些常见不必要CSS样式 1.与默认CSS样式一致 我 ...
- 关于web开发前端h5框架的选择
关于web开发前端h5框架的选择 看了很多移动版框架都是基于app混合式开发的,不是单独h5网站的基于h5开发的web框架从组件丰富度,兼容性,相关教程来说bootstrap还是最好的react和vu ...
- 嵌入式jetty的HTTP实现
2 嵌入式jetty的HTTP实现 布拉君君 2.1 简单HTTP实现 2.1.1 HTTP SERVER端实现 2.1.1.1 HTTP SERVER端实现概述 在代码中嵌入一个Jetty s ...
- asp.net c# 打开新页面或页面跳转
1.最常用的页面跳转(原窗口被替代):Response.Redirect("XXX.aspx"); 2.利用url地址打开本地网页或互联网:Respose.Write(" ...
- I'm Telling the Truth(二分图)
.I'm Telling the Truth Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- muduo库安装
一.简介 Muduo(木铎)是基于 Reactor 模式的网络库. 二.安装 从github库下载源码安装:https://github.com/chenshuo/muduo muduo依赖了很多的库 ...