#include<iostream>
using namespace std;

int power(int x, int n)
{//分治法,时间复杂度:lgn
    if(x == 0)
    {
        if(n == 0)
            cout << "WRONG INPUT: SIGNIGICANT!!!" << endl;
        return 0;
    }
    if(n == 0)
        return 1;
    int sum = 1;
    int t = power(x, n/2);
    sum = t*t;
    if(n % 2)
        sum *= x;
    return sum;
}

int main()
{
    int x, n;
    while(cin >> x >> n, n != 0 || x != 0)
    {
        cout << x << " to the " << n << " is : " << power(x, n) << endl;
    }
    return 0;
}

相关文章:

  • 2021-11-23
  • 2021-12-21
  • 2022-12-23
  • 2021-09-11
  • 2021-09-29
  • 2021-04-04
  • 2021-09-10
  • 2021-11-19
猜你喜欢
  • 2021-10-13
  • 2021-04-20
  • 2021-09-04
  • 2021-11-08
相关资源
相似解决方案