题记
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.
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
**************************************************************************************************************************
这个题是b!/a!,将两者之间相同元素约掉后,这个式子便转换成(a+1)*(a+2)********b,而如果(a+1)与b之间十位数不同,则一定会乘到类似10,20,30,个位数将会变为0.所以,可以先判断个位数为0的情况
if(b-a>=10){
printf("0\n");
continue;
}
a%=10;
b%=10;
if(b<a)
printf("0\n");
如果十位数相同,则只需要将(a+1),(a+2),,,,b的个位数相乘,可以用取余10,来简化计算,因为,我们只需要求得最后一位数字是多少,所以不用管其他位上的数字
#include <stdio.h>
long long int a,b,d;
int main(){
int c;
while(~scanf("%lld %lld",&a,&b)){
d =1;
c=1;
if(b-a>=10){
printf("0\n");
continue;
}
a%=10;
b%=10;
if(b<a)
printf("0\n");
else{
for(int i=a+1;i<=b;i++){
d*=i;
d%=10;
}
printf("%d\n",d);
}
}
}