码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

时间:2017-10-07 19:47:16      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:cep   1.5   top   lower   otto   port   阶乘   void   margin   

 

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.

Examples
input
2 4
output
2
input
0 10
output
0
input
107 109
output
2
Note

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和b的差大于等于10的时候结果为0.

  当a和b的差小于10的时候,暴力计算就好了(当然,不是把a!和b!)。

Code

 1 /**
 2  * Codeforces
 3  * Problem#869B
 4  * Accepted
 5  * Time: 30ms
 6  * Memory: 0k 
 7  */ 
 8 #include <bits/stdc++.h>
 9 #ifndef WIN32
10 #define Auto "%lld"
11 #else
12 #define Auto "%I64d"
13 #endif
14 using namespace std;
15 
16 long long a, b;
17 
18 inline void init() {
19     scanf(Auto""Auto, &a, &b);    
20 }
21 
22 inline void solve() {
23     if(b - a > 10)    puts("0");
24     else {
25         int res = 1;
26         for(int i = b % 10, c = 0; c < b - a; c++, i = (i + 9) % 10) {
27             res = (res * i) % 10;
28         }
29         printf("%d\n", res);
30     }
31 }
32 
33 int main() {
34     init();
35     solve();
36     return 0;
37 }

 

 

Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)

标签:cep   1.5   top   lower   otto   port   阶乘   void   margin   

原文地址:http://www.cnblogs.com/yyf0309/p/7635454.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!