[ create a new paste ] login | about

Link: http://codepad.org/tH2z28FI    [ raw code | output | fork | 1 comment ]

outoftime - C++, pasted on Dec 19:
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

using namespace std;

double BinPow(int a, int n){ return (n) ? ( (n&1) ? (a * BinPow(a,n-1)) : (BinPow(a,n>>1)*BinPow(a,n>>1)) ) : (1);}

int main()
{
    int a = 6, n = 4;
    cout << (BinPow(a,n)) << endl;
    return 0;
}


Output:
1
1296


Create a new paste based on this one


Comments:
posted by outoftime on Jan 5
рекурсивное бинарное возведение в степень
reply