CodeForces 869B
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
2 4
2
0 10
0
107 109
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的更多相关文章
- 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 ...
- 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)【A、B、C、E】
Codeforces Round #439 (Div. 2) codeforces 869 A. The Artful Expedient 看不透( #include<cstdio> in ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- C#控件之Repeater控件使用
歡迎大家來討論,修改,一定虛心接受. 1.為什麼使用Repeater控件? 關於把從數據庫讀取的數據綁定到前台頁面,我們可以使用DataGrid.DataGridView以及Repeater來佈局,三 ...
- PHP 多文件打包下载 zip
<?php $zipname = './photo.zip'; //服务器根目录下有文件夹public,其中包含三个文件img1.jpg, img2.jpg, img3.jpg,将这三个文件打包 ...
- Bootstrap-tagsinput标系统使用心得
最近工作中由于需求使用到了Bootstrap-tagsinput标系统,我的需求是: 1)能够从后台数据库获取标签信息展示到前端页面: 2)能够实现输入标签添加到后台,并ajax刷新页面: 3)能够实 ...
- 条形码生成库 BarcodeLib
官方介绍 在ASP.NET,Windows,Reporting Service,Crystal Reports 和 RDLC Reports应用程序中轻松生成条形码 生成准确的条形码图像,并可以保存为 ...
- Post/Redirect/Get
参考地址:https://www.cnblogs.com/TonyYPZhang/p/5424201.html 参考资料:Flask Web开发:基于Python的Web应用开发实战 Post/Red ...
- Hibernate 应知应会
Hibernate 的关联关系的配置: 一对一外键约束: 举例子是一个丈夫和妻子:[一个丈夫只能有一位妻子] 表结构: CREATE TABLE `tbl_hus` ( `uuid` ) NOT NU ...
- 一个Vue实例-添加、显示列表、删除
<link href="~/Content/css/bootstrap-theme.min.css" rel="stylesheet" /> < ...
- grub引导启动 win10 Ubantu 凤凰OS 三系统
在Ubantu OS下,用文件管理器打开系统磁盘下的 boot文件夹,然后用管理员身份打开grub文件夹,然后打开grub.cfg(用记事本打开) 4. 在grub.cfg文件里面找到下一段内容(比较 ...
- 【比赛】HNOI2018 寻宝游戏
考试的时候就拿了30points滚粗了 听说myy对这题的倒推做法很无奈,官方题解在此 正解思路真的很巧妙,也说的很清楚了 就是分别考虑每一位,会发现题解中的那个性质,然后把询问的二进制数按照排序后的 ...
- 【CF528D】Fuzzy Search(FFT)
[CF528D]Fuzzy Search(FFT) 题面 给定两个只含有\(A,T,G,C\)的\(DNA\)序列 定义一个字符\(c\)可以被匹配为:它对齐的字符,在距离\(K\)以内,存在一个字符 ...