Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // x ^ y % n
- int modpow(int x, int y, int n) {
- int ret = 1;
- for (; y; x = x * x % n, y >>= 1) {
- if (y & 1) {
- ret = ret * x % n;
- }
- }
- return ret;
- }
- int main(void) {
- printf("2 ^ 10 %% 7 = %d\n", modpow(2, 10, 7));
- printf("2 ^ 20 %% 7 = %d\n", modpow(2, 20, 7));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement