在 C++ 中查找给定五位数乘方末尾五位数字
此题中,我们给出数字 N。我们的任务是找出给定五位数乘方后,末尾五位数字。
让我们举个例子来理解此问题,
输入: N = 25211
输出
解决方案方法
为了解决此问题,我们只需要找出所得值的后五位数字。因此,我们将通过查找数字的五位数余数,来求出每次幂次增加后数字的最后一位。 最后返回 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<<"The last five digits of "<<n<<" raised to the power 5 are "<<result;
}
int main() {
int n = 12345;
lastFiveDigits(n);
return 0;
}输出
The last five digits of 12345 raised to the power 5 are 65625
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP