codeforces The Eternal Immortality 题解
来源:互联网 发布:qq三国陆逊打技能数据 编辑:程序博客网 时间:2024/06/04 08:12
传送门:codeforces
题目大意:给你两个数a,b,其中0 ≤ a ≤ b ≤ 1018,问b!/a!的最后一位的值,其中!为阶乘符号。
Examples
Input
2 4
Output
2
Input
0 10
Output
0
Input
107 109
Output
2
思路:由于a和b都很大,我们肯定是不可能直接计算结果的。我们注意到b一定不小于a,b!/a!一定是整数,为什么呢?因为两者有重合的部分:1*2*3*…*a,所以这个题可以化简一下:b!/a!=(a+1)*(a+2)*…*b,我们只需要计算这个乘法的值就好了。我们又发现当乘数个数大于10(其实大于5就够了)的时候,最低位一定是0,很好理解,任何数乘以0都为0.
具体实现:如果b-a的值大于等于10则结果为0,否则暴力求解。
注意:当a为0的时候需要让a+1,否则会出错。
#include<bits/stdc++.h> using namespace std;typedef long long LL;int main() {LL i,a,b,ans;while(~scanf("%lld%lld",&a,&b)){if(a==0) a=1;ans=1;if(b-a>=10) printf("0\n");else {for(i=a+1;i<=b;i++){ans*=i;ans%=10;}printf("%lld\n",ans);}}return 0;}
阅读全文
1 0
- codeforces The Eternal Immortality 题解
- Codeforces 869B. The Eternal Immortality
- CodeForces 869B The Eternal Immortality
- codeforces 869B The Eternal Immortality
- codeforces 869B The Eternal Immortality
- Codeforce The Eternal Immortality
- Codeforces869B The Eternal Immortality
- B. The Eternal Immortality
- Codeforces Round #439 (Div. 2) The Eternal Immortality
- Codeforces Round #439 (Div. 2) B. The Eternal Immortality
- Codeforces Round #439 (Div. 2) B. The Eternal Immortality
- codeforces—— 869B —— The Eternal Immortality
- Codeforces Round #439 (Div. 2) B. The Eternal Immortality
- Codeforces Round #439 (Div. 2) The Eternal Immortality
- codeforces 869BThe Eternal Immortality
- CF 869 B. The Eternal Immortality【数学】
- codeforces The Wall - 题解
- codeforces Gym 100187 A. Potion of Immortality
- 有N个孩子站在一条线上。 每个孩子都被分配一个评分值。你给这些孩子,每个孩子必须至少有一个糖果具有较高评级的儿童比邻居获得更多的糖果。 你必须给予的最低
- Pandas统计分析基础
- NP[阶乘取余]
- NP
- svg字体图标
- codeforces The Eternal Immortality 题解
- NSOperation
- 最严风暴之后,比特币等虚拟货币活得怎么样?
- 大陆出现首例iPhone 8电池爆裂事件;小米被指责盗用视频素材丨价值早报
- 人生苦短,就不洗碗 | 钛空舱
- bzoj2957楼房重建(线段树)
- 详解独角兽应该具备的6个特点,创业者必看
- POJ
- 设计模式系列之适配器模式