Skip to content

Commit

Permalink
Merge pull request #36 from jatinpandey77/patch-1
Browse files Browse the repository at this point in the history
Added Modular Exponentiation algorithm
  • Loading branch information
i-vishi authored Oct 2, 2018
2 parents 7e81ecd + 66d737e commit 2bfbf5f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Common Algorithms/modular-exp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>

int power(int x, unsigned int y, int p) {
int res = 1;
x = x % p;

while (y > 0) {
if (y & 1)
res = (res*x) % p;
y = y>>1; // y = y/2
x = (x*x) % p;
}
return res;
}
int main() {
printf("%u", power(2, 32, 1024));
return 0;
}

0 comments on commit 2bfbf5f

Please sign in to comment.