CF899D.Shovel Sale

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 2 burles, 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.

Polycarp 的商店中有 nn 把铲子。第 ii 把铲子的价格为 ii 卢布,即第一把铲子价格为 1 卢布,第二把铲子价格为 2 卢布,第三把铲子价格为 3 卢布,依此类推。Polycarp 希望以成对的方式销售铲子。

如果一对铲子的总价格以若干个连续的数字 9 结尾,则顾客更有可能购买该对铲子。因此,Polycarp 希望选择一对铲子进行销售,使得它们的总价格以尽可能多的连续 9 结尾。例如,若他选择价格分别为 12345 和 37454 的两把铲子,则总价格为 49799,以两个 9 结尾。

你需要计算满足以下条件的铲子对的数量:其总价格以最大可能数量的连续 9 结尾。若某把铲子出现在其中一对中但不出现在另一对中,则认为这两对是不同的。

输入格式

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

第一行包含一个整数 nn(2≤n≤1092 \leq n \leq 10^9)—— Polycarp 店铺中铲子的数量。

输出格式

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.

输出满足“其总价格以最多数量的 9 结尾”这一条件的铲子对的数量。

注意:末尾最多可能有 0 个 9,此时你需要统计所有满足该条件的方案数。

保证对于每个 $ n \leq 10^9 $,答案不超过 $ 2 \cdot 10^9 $。

输入输出样例

  • 输入#1

    7

    输出#1

    3
  • 输入#2

    14

    输出#2

    9
  • 输入#3

    50

    输出#3

    1

说明/提示

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 个数字 9。波利卡普可以选择以下几对铲子来实现这一目标:

  • 2 和 7;
  • 3 和 6;
  • 4 和 5。

在第二个例子中,两把铲子总价格末尾的数字 9 的最大个数为 1。以下几对铲子满足波利卡普的要求:

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

在第三个例子中,必须选择第 49 把和第 50 把铲子,因为它们的价格之和为 99,即末尾数字 9 的个数为 2,这是当 $ n = 50 $ 时所能达到的最大值。

输入解题思路,AI测评打分。不知道怎么写?

首页