Skip to content

Instantly share code, notes, and snippets.

@haroldxin
Last active August 29, 2015 14:06
Show Gist options
  • Save haroldxin/64aeb77b6588cbed0f45 to your computer and use it in GitHub Desktop.
Save haroldxin/64aeb77b6588cbed0f45 to your computer and use it in GitHub Desktop.
QUICKLY MI
#include <iostream>
#include <stdio.h>
using namespace std;
typedef unsigned int uint;
void pow(uint x,uint y){
uint pow;
if(x == 1)
cout << 1;
if(x != 0 && y == 0)
cout << 1;
if(x == 0 && y == 0)
throw "invalid argument";
pow=1;
while (y>0){
if(y%2==1)pow=pow*x;
x=x*x;
y=y/2;
}
cout << pow;
}
int main (){
int a,b;
cin >> a;
cin >> b;
pow(a,b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment