解题思路: 快速幂
注意事项:
参考代码:
#include <iostream> // #include <sstream> #include <cstdio> // #include <algorithm> // #include <cmath> // #include <cstdlib> // #include <cstring> // #include <cctype> // #include <string> // #include <climits> // #include <map> // #include <vector> // #include <list> // #include <set> using namespace std; // const int maxn = 104; // const long long MOD = 100000007; // const double PI = acos(-1.0); int main() { int a, n; cin >> a >> n; if (a == 0) { // 特殊情况判断 printf("0\n"); return 0; } int ans(1), mul(a); // 快速幂,ans保存答案,mul保存每次要乘的数 while (n) { if (n & 1) ans *= mul; n >>= 1; mul *= mul; } printf("%d\n", ans); return 0; }
0.0分
0 人评分
模拟计算器 (C语言代码)浏览:896 |
Tom数 (C++代码)浏览:829 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:262 |
A+B for Input-Output Practice (C语言代码)浏览:468 |
小O的乘积 (C++代码)浏览:756 |
孤独的骑士 (C语言代码)浏览:1372 |
1218题求大神帮忙看看怎么不能过浏览:698 |
开心的金明浏览:1546 |
1277题解浏览:577 |
WU-简单的a+b (C语言代码)浏览:864 |