codeforces 868B The Eternal Immortality【暴力+trick】
1 second
256 megabytes
standard input
standard output
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.
The first and only line of input contains two space-separated integers a and b (0 ≤ a ≤ b ≤ 1018).
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
2 4
2
0 10
0
107 109
2
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.
【题意】:如hint
【分析】:先化简 + 特判ans==0 + 因为只取最后一位每次可以%10防溢出
【代码】:
#include <bits/stdc++.h> using namespace std; int main()
{
long long a,b;
long long ans;//Take care, integer overflow can emerge everywhere!
while(~scanf("%lld%lld",&a,&b))
{
ans=;
for(long long i=a+;i<=b;i++)
{
ans=(ans*(i%))%;
if(!ans) break;
}
printf("%lld\n",ans);
}
return ;
} /*Hence we can multiply the integers one by one,
only preserving the last digit (take it modulo 10 whenever possible), and stop when it becomes 0.
It's obvious that at most 10 multiplications are needed before stopping,
and it's not hard to prove a tighter upper bound of 5.*/
codeforces 868B The Eternal Immortality【暴力+trick】的更多相关文章
- CodeForces - 869B The Eternal Immortality
题意:已知a,b,求的最后一位. 分析: 1.若b-a>=5,则尾数一定为0,因为连续5个数的尾数要么同时包括一个5和一个偶数,要么包括一个0. 2.若b-a<5,直接暴力求即可. #in ...
- Codeforces Round #439 (Div. 2) B. The Eternal Immortality
B. The Eternal Immortality 题目链接http://codeforces.com/contest/869/problem/B 解题心得:题意就是给出a,b,问(a!)/(b!) ...
- 【Codeforces Round #439 (Div. 2) B】The Eternal Immortality
[链接] 链接 [题意] 求b!/a!的最后一位数字 [题解] b-a>=20的话 a+1..b之间肯定有因子2和因子5 答案一定是0 否则暴力就好 [错的次数] 在这里输入错的次数 [反思] ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力
Couple Cover Time Limit: 3000MS Memory Limit: 524288KB 64bit IO Format: %I64d & %I64u Descri ...
- Codeforces 626D Jerry's Protest(暴力枚举+概率)
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- codeforces 650D D. Image Preview (暴力+二分+dp)
题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...
随机推荐
- [bzoj4860] [BeiJing2017]树的难题
Description 给你一棵 n 个点的无根树.树上的每条边具有颜色. 一共有 m 种颜色,编号为 1 到 m.第 i 种颜色的权值为 ci.对于一条树上的简单路径,路径上经过的所有边按顺序组成一 ...
- [NOI2017]游戏 2-sat
---题面--- 题解: 首先观察到,如果没有x的话,这就是一个2-sat问题. 建图方式:对于限制d1 c1 d2 c2,其中d1, d2分别代表比赛编号,c1, c2代表出场的赛车. 1,如果d1 ...
- Linux总结(二)
1. 虚拟机安装 a)双系统(不建议初学者一开始去装) b)般建议使用虚拟机来操作试验环境 c)好处:可以模拟真实的环境进行各种的试验和操作 d)在启动之后,在操作的时候会占用一部分的系统资源 1 ...
- 网络编程:listen函数
listen函数仅由TCP服务器调用,它做两件事: 当socket函数创建一个套接字时,它被假设为一个主动套接字,也就是说,它是一个将调用connect发起连接的客户套接字.listen函数把一个未连 ...
- 如何抓取开了gzip的网页
有时候用 file_get_contents() 函数抓取网页会发生乱码现象.有两个原因会导致乱码,一个是编码问题,一个是目标页面开了Gzip. 编码问题好办,把抓取到的内容转下编码即可($conte ...
- 怎么把centos虚拟机zip文件导入vm虚拟机中
执行以上三步就可以将一个压缩的centoszip文件导入到虚拟机中
- centos安装net-speeder
以前介绍过VPS上安装锐速对VPS的加速效果,但是这货对 Linux 内核有要求,一般就只能在XEN或者KVM的机子上安装.不过还好锐速有一个免费的代替品:net-speeder,所以这里介绍一下 D ...
- 利用java.lang.reflect.Constructor动态实例化对象
} } } } } Student t = co ...
- POJ 1064---二分搜索法
///2.假定一个解并判断是否可行 ///POJ1064 /** Q:有N条绳子,长度分别为Li,从中切割出k条长度相同的绳子, 这K条绳子最长能有多长?保留两位小数 A: 二分搜索模型. 条件C(x ...
- hdu 2544 最短路 (dijkstra,floyd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544 题目大意:找到两点间最短的距离值. 代码一:(dijkstra算法) #include < ...