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.

Sample Input

Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2

Hint

扫描二维码关注公众号,回复: 2540382 查看本文章

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.

水题,但对我来说并不水。

开始没看数的大小就交了一发,T了。回过头来,发现数很大,当时觉得long long 也存不了,就往字符串的方向想,然后觉得用字符串求阶乘同样会超时,还是要回到数上,同时想起来,long long 能存得了1e18的数。但是还是找不到规律在哪??

题目要求了只求个位数,那么很显然,如果在乘的过程中出现了末尾为零的数,最后乘的结果也必然是零,什么时候会有零的出现,当然(最多是)一个数加了10。所以只需要判从a*(a+!)*(a+2)......(a+10)就行,这样就不会超时了.

为什么当时你想了一个小时都没有想出来?Why??? Why!!!!!!!  归根结底,还是你太菜了,understand ?  Are you understand ? Yeah , I'm understand .

总结一下吧,某个式子相乘后的最后一位:1、与这个式子中某个数的个位是否为零密切相关。

2、与这个式子中所有数的个位相乘有关。

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<cmath>
 5 #include<algorithm>
 6 #include<queue>
 7 #include<stack>
 8 #include<deque>
 9 #include<map>
10 #include<iostream>
11 using namespace std;
12 typedef long long  LL;
13 const double pi=acos(-1.0);
14 const double e=exp(1);
15 const int N = 100010;
16 
17 #define lson i << 1,l,m
18 #define rson i << 1 | 1,m + 1,r
19 
20 int main()
21 {
22     LL i,j,x,y,p;
23     p=1;
24     scanf("%lld%lld",&x,&y);
25     for(i=x+1; i<=y; i++)
26     {
27         p=(p*i)%10;
28         if(p==0)
29             break;
30     }
31 
32     if(i<=y)
33         printf("0\n");
34     else
35         printf("%lld\n",p);
36     return 0;
37 
38 }
View Code

猜你喜欢

转载自www.cnblogs.com/daybreaking/p/9417773.html