Codeforces869b the eternal immortality

阅读全文大概需要 2分钟
本文总阅读量
Posted by yjjr's blog on February 6, 2018

标签:模拟,数学

Even if the world is full of counterfeits,I still regard it as wonderful.

Pile up herbs and incense, and arise againfrom the flames and ashes of its predecessor — as is known to many, thephoenix does it like this.

The phoenix has a rather long lifespan, andreincarnates itself once everya! years. Here a! denotes thefactorial of integer a, that is,a! = 1 × 2 × ... × a. Specifically, 0! = 1.

Koyomi doesn't care much about this, butbefore he gets into another mess with oddities, he is interested in the numberof times the phoenix will reincarnate in a timespan ofb! years, thatis, . Note that when b ≥ a this value is always integer.

As the answer can be quite large, it wouldbe enough for Koyomi just to know the last digit of the answer in decimalrepresentation. And you're here to provide Koyomi with this knowledge.

Input

The first and only line of input containstwo space-separated integersa and b (0 ≤ a ≤ b ≤ 1018).

Output

Output one line containing a single decimaldigit — 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+1->b的乘积即可,注意如果ans已经等于0,那么直接跳出循环输出0

Code

#include<bits/stdc++.h>
#define rep(i,a,b) for(long long i=a;i<=b;i++)
#define dep(i,a,b) for(long long i=a;i>=b;i--)
#define LL unsigned long long
using namespace std;
LL a,b,ans=1;
 
int main()
{
	cin>>a>>b;
	rep(i,a+1,b){ans=(ans*i)%10;if(ans==0)break;}
	cout<<ans<<endl;
	return 0;
} 




本文可以转载,但必须附上原文链接,否则你会终生找不到妹子!!!欢迎关注我的CSDN: ahyjjr