Codeforces Round #439 (Div.2)
来源:互联网 发布:js float 保留两位小数 编辑:程序博客网 时间:2024/05/29 19:57
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.
题意:
有a,b两个数求 b!/a! 的个位数
思路:
只要a+1 ~ b 中有一个数的个位数为0则最终答案个位数一定为零
分类讨论,注意特例
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;#define LL long longint main(){ LL a,b,ans = 1; scanf("%lld%lld",&a,&b); if(a==b){ printf("1\n"); return 0; } LL c = b-a; a=(a+1)%10,b%=10; if(a>b||c>=10) printf("0\n"); else{ for(;a<=b;a++) ans*=a,ans%=10; printf("%lld\n",ans); } return 0;}
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div.2)
- Codeforces Round #439 (Div.2)
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div. 2)
- Codeforces Round #439 (Div. 2) C
- Codeforces Round #439 (Div. 2) 题解
- Codeforces Round #439 (Div. 2) 总结
- Codeforces Round #439 (Div. 2)A,B
- Codeforces Round #439 (Div. 2)E详解
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Spring Data & JPA
- 模板方法模式
- Java 中的 static 使用之静态方法
- lua脚本学习8
- Asp.net Core 2.0+EntityFrameWorkCore 2.0添加数据迁移
- Codeforces Round #439 (Div.2)
- 线性表
- MOOS例程HelloWorld-详细注释
- 2017 10 08 NOIP2017模拟赛
- 数据结构顺序表实现
- 10个重要的Linux ps命令实战
- lua脚本学习9
- 内部类反序列化问题(fastjson exception: create instance error)
- 使用VS Code编译运行C/C++程序