Last active
July 7, 2019 01:40
-
-
Save sujimodern/295912c78f7f287ec1edb1624406bdf2 to your computer and use it in GitHub Desktop.
Fermat's little theorem
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> | |
int power_mod(int b, int e, int m) { | |
int r = 1; | |
for (int i = 0; i < e; ++i) { | |
r = (r * b) % m; | |
} | |
return r; | |
} | |
int fermat(int a, int p) { | |
return power_mod(a, p - 1, p); | |
} | |
int main() { | |
int a = 8; | |
int p = 11; | |
int r = fermat(a, p); | |
printf("%d\n", r); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment