Quick power: quickpow, power: quickpow
As we all know, quick power is the most common method to optimize the power operation of the logarithm. When learning the idea of "quick power", the idea of division and governance is easy for everyone to use simple recursion.
But in fact, in addition to recursion, a better method will be a simple WHILE loop. Below is the code:
# Include <iostream> # include <cstdio> # include <algorithm> # include <cmath> # include <vector> using namespace std; int quickpow (int x, int y) {int n = 1; while (y! = 0) {if (y & 1) n * = x; x = x * x; y = y> 1;} return n ;}int main () {int a, B; scanf ("% d", & a, & B); printf ("% d \ n", quickpow (a, B ));}
* Remember to use bitwise operations to optimize QWQ.
PS: This is my first BLOG post. Here, I set up the FLAG to carefully refresh the questions, update the BLOG, and cheer up to become an ambitious QAQ.