typedef long long ll; #include <iostream> using namespace std; ll fast_pwoer(ll base,ll index,ll mod) { ll ans = 1; base %= mod; //指数为循环次数 while (index) { //判断奇偶性 if (index % 2 == 1) { ans = (ans * base) % mod; } base = (base * base) % mod; index /= 2; } return ans; } int main() { int p,m; cin >> p >> m; cout << (fast_pwoer(2,p,m)) << endl; return 0; }
详细解题思路请看我的另一篇题解:
0.0分
1 人评分
点我有惊喜!你懂得!浏览:2705 |
兰顿蚂蚁 (C++代码)浏览:1089 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:701 |
1908题解浏览:633 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:504 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:505 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:324 |
复数求和 (C语言代码)浏览:915 |
理财计划 (C语言代码)浏览:465 |
判定字符位置 (C语言代码)浏览:784 |