请完善下面的程序该程序使用分治法求 xp mod m 的值。输入:三个不超过 10000 的正整数 xpm。输出:xp mod m 的值。提示:若 p 为偶数xp=x2 p2;若 p 为奇数xp=xx2 p-12。#include iostreamusing namespace std;int x p m i result;int main cin x p m; resul
#include
using namespace std;
int x, p, m, i, result;
int main() {
cin >> x >> p >> m;
result = 1;
while (p > 0) {
if (p % 2 == 1)
result = (result * x) % m;
p /= 2;
x = (x * x) % m;
}
cout << result << endl;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/iOTU 著作权归作者所有。请勿转载和采集!