-
-
Save gandaro/1979625 to your computer and use it in GitHub Desktop.
Square and multiply
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
uint64_t bin_exp(uint32_t x, uint32_t k) { | |
uint64_t res = 1; | |
uint32_t mask = 1 << 31; | |
while (mask) { | |
res *= res; | |
if (k & mask) | |
res *= x; | |
mask >>= 1; | |
} | |
return res; | |
} | |
int main(void) { | |
for (int i = 1; i <= 15; i++) | |
for (int j = 2; j <= 15; j++) | |
printf("%d^%d = %llu\n", i, j, bin_exp(i, j)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment