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

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、与这个式子中所有数的个位相乘有关。

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp();
const int N = ; #define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r int main()
{
LL i,j,x,y,p;
p=;
scanf("%lld%lld",&x,&y);
for(i=x+; i<=y; i++)
{
p=(p*i)%;
if(p==)
break;
} if(i<=y)
printf("0\n");
else
printf("%lld\n",p);
return ; }

CodeForces 869B的更多相关文章

  1. 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 ...

  2. CodeForces - 869B The Eternal Immortality

    题意:已知a,b,求的最后一位. 分析: 1.若b-a>=5,则尾数一定为0,因为连续5个数的尾数要么同时包括一个5和一个偶数,要么包括一个0. 2.若b-a<5,直接暴力求即可. #in ...

  3. Codeforces Round #439 (Div. 2)【A、B、C、E】

    Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. HTML&CSS实体

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  2. 在MySQL中如何使用覆盖索引优化limit分页查询

    背景 今年3月份时候,线上发生一次大事故.公司主要后端服务器发生宕机,所有接口超时.宕机半小时后,又自动恢复正常.但是过了2小时,又再次发生宕机. 通过接口日志,发现MySQL数据库无法响应服务器.在 ...

  3. 【Linux学习笔记】Linux C中内联汇编的语法格式及使用方法(Inline Assembly in Linux C)

    http://blog.csdn.net/slvher/article/details/8864996 https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm. ...

  4. LoadRunner脚本增强技巧之自动关联

    为什么要做关联,原理很简单,录制脚本的时候,服务器会给用户一个唯一的认证码来进行操作,当再次回放脚本的时候服务器又会给一个全新的认证码,而录制好的脚本是写死的,还是拿老的认证码提交,肯定会导致脚本执行 ...

  5. 第165天:canvas绘制圆环旋转动画

    canvas绘制圆环旋转动画——面向对象版 1.HTML 注意引入Konva.js库 <!DOCTYPE html> <html lang="en"> &l ...

  6. 【Python】Python基础教程系列目录

    Python是一个高层次的结合了解释性.编译性.互动性和面向对象的脚本语言. 在现在的工作及开发当中,Python的使用越来越广泛,为了方便大家的学习,Linux大学 特推出了 <Python基 ...

  7. FZU2121_神庙逃亡

    水题.直接解二次方程判断点的高度即可. #include <iostream> #include <cstring> #include <cstdio> #incl ...

  8. 认识User-Agent

    Windows NT 10 对应操作系统 windows 10 Windows NT 6.3 对应操作系统 windows 8.1 Windows NT 6.2 对应操作系统 windows 8 Wi ...

  9. Race to 1 UVA - 11762 (记忆dp概率)

    #include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...

  10. c语言中,指针加1的情况.指针变量详细介绍

    指针是一个特殊的变量,它里面存储的数值被解释成为内存里的一个地址. 要搞清一个指针需要搞清指针的四方面的内容: 指针的类型, 指针所指向的 类型, 指针的值或者叫指针所指向的内存区, 还有指针本身所占 ...