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 ...
随机推荐
- BZOJ4544 椭圆上的整点(数论)
https://www.cnblogs.com/Gloid/p/9538413.html 基本思路没有太大差别.得到2n=d(a2+3b2),其中d=gcd(n-x,n+x),n-x==a2& ...
- HDU 6194 string string string(后缀数组+RMQ)
string string string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- Visaul Studio 常用快捷键动画演示
从本篇文章开始,我将会陆续介绍提高 VS 开发效率的文章,欢迎大家补充~ 在进行代码开发的时候,我们往往会频繁的使用键盘.鼠标进行协作,但是切换使用两种工具会影响到我们的开发速度,如果所有的操作都可以 ...
- JS知识总结
1.javascript继承机制 原型继承,访问对象属性时,如果对象内部有就返回,找不到就会从对象原型指向的对象原型中查找,一层一层的查找,直到最顶层的对象原型还找不到,就返回undefined. 2 ...
- HDU 5878---预处理+二分查找
给一个数n,让你求一个大于等于n的最小的满足题意中2^a*3^b*5^c*7^d的数字. 思路: #include<iostream> #include<cstdio> #in ...
- import as from import 区别
在python中import或者from…import是用来导入相应的模块.那每一种有什么具体的差别呢? 一.import 只有import,为最简单的引入对应的包.例如: import ...
- MDK stm32 仿真
直接选择simulator,仿真时报错 *** error 65: access violation at 0x40021000 : no 'read' permission 修改系统配置,原配置如下 ...
- JS高级技巧(简洁版)
高级函数 由于在JS中,所有的函数都是对象,所以使用函数指针十分简单,也是这些东西使JS函数有趣且强大 安全的类型检测 JS内置的类型检测机制并不是完全可靠的 typeof 操作符返回一个字符串,表示 ...
- windows注册表存储位置
win7/8/10 通常情况: HKEY_LOCAL_MACHINE \SYSTEM : \system32\config\system HKEY_LOCAL_MACHINE \SAM : \syst ...
- django2.0的reverse
导入: 官方文档地址:https://yiyibooks.cn/xx/Django_1.11.6/topics/http/urls.html from django.urls import rever ...