B. The Eternal Immortality

Codeforces
IDCF869B
Time1000ms
Memory256MB
Difficulty
math
English · Original
Chinese · Translation
Formal · Original
_Even if the world is full of counterfeits, I still regard it as wonderful._ Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every _a_! years. Here _a_! denotes the factorial of integer _a_, that is, _a_! = 1 × 2 × ... × _a_. Specifically, 0! = 1. Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of _b_! years, that is, . Note that when _b_ ≥ _a_ this value is always integer. As the answer can be quite large, it would be enough for Koyomi just to know **the last digit of the answer in decimal representation**. And you're here to provide Koyomi with this knowledge. ## Input The first and only line of input contains two space-separated integers _a_ and _b_ (0 ≤ _a_ ≤ _b_ ≤ 1018). ## Output Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. [samples] ## Note In the first example, the last digit of is 2; In the second example, the last digit of is 0; In the third example, the last digit of is 2.
_即使世界充满赝品,我仍视其为美妙。_ 堆积草药与香料,从其前身的火焰与灰烬中重生——正如许多人所知,凤凰正是如此行事。 凤凰拥有相当长的寿命,每 #cf_span[a!] 年重生一次。这里 #cf_span[a!] 表示整数 #cf_span[a] 的阶乘,即 #cf_span[a! = 1 × 2 × ... × a]。特别地,#cf_span[0! = 1]。 Koyomi 并不太关心这一点,但在他再次陷入怪异之事前,他感兴趣的是在 #cf_span[b!] 年的时间跨度内,凤凰将重生多少次,即 。注意当 #cf_span[b ≥ a] 时,该值始终为整数。 由于答案可能非常大,Koyomi 只需知道答案在十进制表示下的*最后一位数字*即可。而你正是要为 Koyomi 提供这一信息。 输入的第一行且唯一一行包含两个用空格分隔的整数 #cf_span[a] 和 #cf_span[b](#cf_span[0 ≤ a ≤ b ≤ 1018])。 输出一行,包含一个十进制数字——即 Koyomi 所关心的值的最后一位数字。 在第一个示例中, 的最后一位数字是 #cf_span[2]; 在第二个示例中, 的最后一位数字是 #cf_span[0]; 在第三个示例中, 的最后一位数字是 #cf_span[2]。 ## Input 输入的第一行且唯一一行包含两个用空格分隔的整数 #cf_span[a] 和 #cf_span[b](#cf_span[0 ≤ a ≤ b ≤ 1018])。 ## Output 输出一行,包含一个十进制数字——即 Koyomi 所关心的值的最后一位数字。 [samples] ## Note 在第一个示例中, 的最后一位数字是 #cf_span[2];在第二个示例中, 的最后一位数字是 #cf_span[0];在第三个示例中, 的最后一位数字是 #cf_span[2]。
**Definitions** Let $ a, b \in \mathbb{Z} $ with $ 0 \leq a \leq b \leq 10^{18} $. **Objective** Compute the last decimal digit of $ \frac{b!}{a!} $. **Note** Since $ b \geq a $, $ \frac{b!}{a!} = (a+1)(a+2)\cdots b $ is an integer. We seek $ \left( \prod_{i=a+1}^{b} i \right) \mod 10 $.
Samples
Input #1
2 4
Output #1
2
Input #2
0 10
Output #2
0
Input #3
107 109
Output #3
2
API Response (JSON)
{
  "problem": {
    "name": "B. The Eternal Immortality",
    "description": {
      "content": "_Even if the world is full of counterfeits, I still regard it as wonderful._ Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF869B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "_Even if the world is full of counterfeits, I still regard it as wonderful._\n\nPile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "_即使世界充满赝品,我仍视其为美妙。_\n\n堆积草药与香料,从其前身的火焰与灰烬中重生——正如许多人所知,凤凰正是如此行事。\n\n凤凰拥有相当长的寿命,每 #cf_span[a!] 年重生一次。这里 #cf_span[a!] 表示整数 #cf_span[a] 的阶乘,即 #cf_span[a! = 1 × 2 × ... × a]。特别地,#cf_span[0! = 1]。\n\nKoyomi 并不太关心...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ a, b \\in \\mathbb{Z} $ with $ 0 \\leq a \\leq b \\leq 10^{18} $.  \n\n**Objective**  \nCompute the last decimal digit of $ \\frac{b!}{a!} $.  \n\n**Note**  \nSince $ b \\geq a $, $ \\frac{b...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments