Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

Posted 阿波罗2003

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)相关的知识,希望对你有一定的参考价值。

 

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.

Examples
input
2 4
output
2
input
0 10
output
0
input
107 109
output
2
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.

 


  题目大意 给定a和b求b的阶乘除以a的阶乘的商的末尾数字。

  显然,当a和b的差大于等于10的时候结果为0.

  当a和b的差小于10的时候,暴力计算就好了(当然,不是把a!和b!)。

Code

 1 /**
 2  * Codeforces
 3  * Problem#869B
 4  * Accepted
 5  * Time: 30ms
 6  * Memory: 0k 
 7  */ 
 8 #include <bits/stdc++.h>
 9 #ifndef WIN32
10 #define Auto "%lld"
11 #else
12 #define Auto "%I64d"
13 #endif
14 using namespace std;
15 
16 long long a, b;
17 
18 inline void init() {
19     scanf(Auto""Auto, &a, &b);    
20 }
21 
22 inline void solve() {
23     if(b - a > 10)    puts("0");
24     else {
25         int res = 1;
26         for(int i = b % 10, c = 0; c < b - a; c++, i = (i + 9) % 10) {
27             res = (res * i) % 10;
28         }
29         printf("%d\n", res);
30     }
31 }
32 
33 int main() {
34     init();
35     solve();
36     return 0;
37 }

 

 

以上是关于Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学

Codeforces Round #439 (Div. 2)

C - The Intriguing Obsession /* Codeforces Round #439 */ (dp )

Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分