题目
描述:
正整数M 的N次方有可能是一个非常大的数字,我们只求该数字的最后三位
例1:
比如输入5和3 ,5的3次方为125,则输出为125
例2:
比如输入2和10 2的10次方为1024 ,则输出结果为24
例3:
比如输入111和5 111的5次方为116850581551,则输出结果为551
练习阶段:
初级
代码
/*---------------------------------------
* 日期:2015-07-04
* 作者:SJF0115
* 题目:求M的N次方的最后三位
* 来源:华为机试练习题
-----------------------------------------*/
#include <iostream>
#include "oj.h"
using namespace std;
unsigned int GetLastThreeNumOfResult (unsigned int m, unsigned int n){
unsigned int result = 1;
for(int i = 0;i < n;++i){
result = (result * (m % 1000)) % 1000;
}//for
return result;
}
//求n!/m!的最后一位
B. The Eternal Immortality
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
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
Copy
2 4
output
2
input
Copy
0 10
output
0
input
Copy
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.
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
int main()
{
long long result = 1;
long long n, m;
cin >> m >> n;
long long point = n - m;
if (point >= 10) {
cout << 0;
return 0;
}
for (long long i = n; point > 0; i--)
{
result = result * (i % 10) % 10;
point--;
}
cout << result << endl;
}