A. Reflection

Codeforces
IDCF86A
Time2000ms
Memory256MB
Difficulty
math
English · Original
Chinese · Translation
Formal · Original
For each positive integer _n_ consider the integer ψ(_n_) which is obtained from _n_ by replacing every digit _a_ in the decimal notation of _n_ with the digit (9  -  _a_). We say that ψ(_n_) is the _reflection_ of _n_. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8. Let us call the _weight_ of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10·89 = 890. Your task is to find the maximum weight of the numbers in the given range \[_l_, _r_\] (boundaries are included). ## Input Input contains two space-separated integers _l_ and _r_ (1 ≤ _l_ ≤ _r_ ≤ 109) — bounds of the range. ## Output Output should contain single integer number: maximum value of the product _n_·ψ(_n_), where _l_ ≤ _n_ ≤ _r_. Please, do not use _%lld_ specificator to read or write 64-bit integers in C++. It is preferred to use _cout_ (also you may use _%I64d_). [samples] ## Note In the third sample weight of 8 equals 8·1 = 8, weight of 9 equals 9·0 = 0, weight of 10 equals 890. Thus, maximum value of the product is equal to 890.
对于每个正整数 $n$,考虑整数 $\psi(n)$,它通过将 $n$ 的十进制表示中的每一位数字 $a$ 替换为数字 $(9 - a)$ 得到。我们称 $\psi(n)$ 为 $n$ 的 _反射_。例如,$192$ 的反射等于 $807$。注意,前导零(如果有)应被省略。因此,$9$ 的反射等于 $0$,$91$ 的反射等于 $8$。 我们称一个数的 _权重_ 为该数与其反射的乘积。因此,数 $10$ 的权重等于 $10 \cdot 89 = 890$。 你的任务是找出给定范围 $[l, r]$(包含端点)内所有数的最大权重。 输入包含两个用空格分隔的整数 $l$ 和 $r$($1 \leq l \leq r \leq 10^9$)——范围的边界。 输出应包含一个整数:最大乘积 $n \cdot \psi(n)$ 的值,其中 $l \leq n \leq r$。 请不要在 C++ 中使用 _%lld_ 标识符读取或写入 64 位整数。建议使用 _cout_(你也可以使用 _%I64d_)。 ## Input 输入包含两个用空格分隔的整数 $l$ 和 $r$($1 \leq l \leq r \leq 10^9$)——范围的边界。 ## Output 输出应包含一个整数:最大乘积 $n \cdot \psi(n)$ 的值,其中 $l \leq n \leq r$。请不要在 C++ 中使用 _%lld_ 标识符读取或写入 64 位整数。建议使用 _cout_(你也可以使用 _%I64d_)。 [samples] ## Note 在第三个样例中,$8$ 的权重等于 $8 \cdot 1 = 8$,$9$ 的权重等于 $9 \cdot 0 = 0$,$10$ 的权重等于 $890$。因此,乘积的最大值等于 $890$。
**Definitions** Let $\psi(n)$ denote the reflection of a positive integer $n$, obtained by replacing each digit $a$ in the decimal representation of $n$ with $9 - a$, and removing leading zeros. Let $w(n) = n \cdot \psi(n)$ denote the weight of $n$. **Constraints** Given integers $l, r \in \mathbb{Z}$ such that $1 \leq l \leq r \leq 10^9$. **Objective** Find $$ \max_{n \in [l, r]} w(n) = \max_{n \in [l, r]} \left( n \cdot \psi(n) \right) $$
Samples
Input #1
3 7
Output #1
20
Input #2
1 1
Output #2
8
Input #3
8 10
Output #3
890
API Response (JSON)
{
  "problem": {
    "name": "A. Reflection",
    "description": {
      "content": "For each positive integer _n_ consider the integer ψ(_n_) which is obtained from _n_ by replacing every digit _a_ in the decimal notation of _n_ with the digit (9  -  _a_). We say that ψ(_n_) is the _",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF86A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "For each positive integer _n_ consider the integer ψ(_n_) which is obtained from _n_ by replacing every digit _a_ in the decimal notation of _n_ with the digit (9  -  _a_). We say that ψ(_n_) is the _...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "对于每个正整数 $n$,考虑整数 $\\psi(n)$,它通过将 $n$ 的十进制表示中的每一位数字 $a$ 替换为数字 $(9 - a)$ 得到。我们称 $\\psi(n)$ 为 $n$ 的 _反射_。例如,$192$ 的反射等于 $807$。注意,前导零(如果有)应被省略。因此,$9$ 的反射等于 $0$,$91$ 的反射等于 $8$。\n\n我们称一个数的 _权重_ 为该数与其反射的乘积。因此,数 ...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $\\psi(n)$ denote the reflection of a positive integer $n$, obtained by replacing each digit $a$ in the decimal representation of $n$ with $9 - a$, and removing leading zeros.  \nL...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments