From 378fe8b8a95cb1419953052857291cc3afbe3fe4 Mon Sep 17 00:00:00 2001 From: aditya Date: Tue, 19 Oct 2021 11:20:54 +0530 Subject: [PATCH] added fast_pow.cpp --- maths/fast_pow.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 maths/fast_pow.cpp diff --git a/maths/fast_pow.cpp b/maths/fast_pow.cpp new file mode 100644 index 0000000..2ea1ec1 --- /dev/null +++ b/maths/fast_pow.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +int fastPower(int a, int b){ + int res = 1; + + while(b > 0){ + if( (b&1) != 0) { + res = res * a; + } + + a = a * a; + b = b >> 1; + } + return res; +} + +int main() { + int m=5,n=2; + cout<