博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #452 (Div. 2) D
阅读量:5095 次
发布时间:2019-06-13

本文共 2501 字,大约阅读时间需要 8 分钟。

D. Shovel Sale

There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.

Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines.

You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other.

Input

The first line contains a single integer n (2 ≤ n ≤ 109) — the number of shovels in Polycarp's shop.

Output

Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines.

Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways.

It is guaranteed that for every n ≤ 109 the answer doesn't exceed 2·109.

Examples
input
7
output
3
input
14
output
9
input
50
output
1
Note

In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose:

  • 2 and 7;
  • 3 and 6;
  • 4 and 5.

In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp:

  • 1 and 8;
  • 2 and 7;
  • 3 and 6;
  • 4 and 5;
  • 5 and 14;
  • 6 and 13;
  • 7 and 12;
  • 8 and 11;
  • 9 and 10.

In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50.

 

 有1,2,3,4...n  n个数,求最多x个9结尾的有多少。5以下是0个9   [5,49]是1个9 [50,499]数两个。。。。

假设有x个9    那么两个数相加有r = 099.....   199...... 299.....   ....   899....等

1、r > 2*n-1时 跳出

2、r < 1+n时 有r//2对

3、r < 2*n时 有(2*n-r+1)//2个

1 import math 2 n = int(input()) 3 if n < 5: 4     print(n*(n-1)//2) 5     exit() 6 a = 0 7 k = int(math.log10(2*n)) 8 for i in range(k): 9     a = a*10+910 ans = 011 for i in range(9):12     r = int(str(i)+str(a))13     if r > 2*n-1:14         break15     elif r < 1+n:16         ans += r//217     elif r < 2*n:18         ans += (n-r+n+1)//219 print(ans)

 

转载于:https://www.cnblogs.com/xingkongyihao/p/8183284.html

你可能感兴趣的文章
关于时间
查看>>
面向对象 阶段性总结
查看>>
[Android] 开发第十天
查看>>
[html]window.open 使用示例
查看>>
.NET下使用socket.io随笔记录
查看>>
操作~拷贝clone()
查看>>
通过this()调用有参构造方法
查看>>
【RN6752】模拟高清AHD芯片或成为车机新标配
查看>>
Android Clipboard(复制/剪贴板)
查看>>
Android中Bitmap,byte[],Drawable相互转化
查看>>
UEFI引导修复教程和工具
查看>>
Using True Type Fonts in XTerm
查看>>
文件读写
查看>>
【转】Linq 求和,求平均值,求最大,求最小,分组,计数
查看>>
关于调整input里面的输入光标大小
查看>>
asp.net实现页面无刷新效果
查看>>
学习总结 for循环语句的应用
查看>>
简聊REST风格
查看>>
php在web服务器中的工作原理
查看>>
String.intern()
查看>>