在这个问题中,给我们一个数字N。我们的任务是找到一个给定的5位数加到5的幂的最后五个数字。
让我们举个例子来了解这个问题,
输入: N = 25211
输出:
要解决该问题,我们只需要找到结果值的最后五位数字即可。因此,通过查找数字的余数5位,我们将在每次幂增加之后找到数字的最后一位。最后返回5的幂后的最后5位数字。
#include <iostream>
using namespace std;
int lastFiveDigits(int n) {
int result = 1;
for (int i = 0; i < 5; i++) {
result *= n;
result %= 100000;
}
cout<<"的最后五位数字 "<<n<<" raised to the power 5 are "<<result;
}
int main() {
int n = 12345;
lastFiveDigits(n);
return 0;
}输出结果的最后五位数字 12345 raised to the power 5 are 65625