#279. NOIP2017PJ-27

NOIP2017PJ-27

27.(完善程序)

(快速幂)请完善下面的程序,该程序使用分治法求 xp mod m 的值。(第一空 2 分,其余 3 分)

输入:三个不超过 10000 的正整数 x,p,m。

输出:xp mod m 的值。

提示:若 p 为偶数,xpx^p = (x2)p/2(x^2)^{p/2};若 p 为奇数,xpx^p = x × (x2)(p1)/2(x^2)^{(p-1)/2}

#include<iostream>
using namespace std;
int x, p, m, i, result;
int main()
{
    cin >> x >> p >> m;
    result = _________________________;
    while (_________________________) {
        if (p % 2 == 1)
            result = _________________________;
        p /= 2;
        x = _________________________;
    }
    cout << _________________________ << endl;
    return 0;
}

①:{{ input(1) }}

②:{{ input(2) }}

③:{{ input(3) }}

④:{{ input(4) }}

⑤:{{ input(5) }}