Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
pow implementation
//Title of this code #include <iostream> using namespace std; // http://stackoverflow.com/questions/5231096/time-complexity-of-power /* IDEA: x => x^2 and n => n/2 (x^2) ^ (n/2) / x^n \ x * (x^2) ^ ((n-1)/2) */ int power(int a, int b) { if (b < 0) return 0; int pow = 1; while ( b ) { if ( b & 1 ) { pow = pow * a; --b; } a = a*a; b >>= 1; // devide by 2 } return pow; } int mypow(int a, int b) { int ret = 1; for (int i = 0; i < b; ++i) ret *= a; return ret; } int main() { std::cout << power(2,10); }
run
|
edit
|
history
|
help
0
ConversionOperator
11 და 16 აპრილს დამუსავებული
codeforces - 545D
ammmma
triplets from vector
an awesome question of basic graph traversal (786A)
simple use of namespace
cppPyProperty
alternate list
weak_ptr and Circle_reference