simplification of (i^j)%k
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm writing a program that is spending major amounts of time of CPU doing power operations. I need to get the modulo of $i^j$ by k. Is there any simplification of $i^j$%k that doesn't involve an exponentiation?
Note: I remove the specification about needing to heck divisibility. I actually need to get the modulo so that I can do more things with it.
exponentiation integers
 |Â
show 7 more comments
up vote
0
down vote
favorite
I'm writing a program that is spending major amounts of time of CPU doing power operations. I need to get the modulo of $i^j$ by k. Is there any simplification of $i^j$%k that doesn't involve an exponentiation?
Note: I remove the specification about needing to heck divisibility. I actually need to get the modulo so that I can do more things with it.
exponentiation integers
What is '^' operator?
– user58697
Jul 16 at 21:26
That's a power operation.
– eftshift0
Jul 16 at 21:26
which language are you using?
– gd1035
Jul 16 at 21:27
I'm working on python.
– eftshift0
Jul 16 at 21:31
2
Perhaps the built in Python function pow could be of use, it takes a third argument which is used to compute modulo: docs.python.org/3/library/functions.html#pow
– gd1035
Jul 16 at 21:49
 |Â
show 7 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm writing a program that is spending major amounts of time of CPU doing power operations. I need to get the modulo of $i^j$ by k. Is there any simplification of $i^j$%k that doesn't involve an exponentiation?
Note: I remove the specification about needing to heck divisibility. I actually need to get the modulo so that I can do more things with it.
exponentiation integers
I'm writing a program that is spending major amounts of time of CPU doing power operations. I need to get the modulo of $i^j$ by k. Is there any simplification of $i^j$%k that doesn't involve an exponentiation?
Note: I remove the specification about needing to heck divisibility. I actually need to get the modulo so that I can do more things with it.
exponentiation integers
edited Jul 16 at 22:12
asked Jul 16 at 21:24
eftshift0
1215
1215
What is '^' operator?
– user58697
Jul 16 at 21:26
That's a power operation.
– eftshift0
Jul 16 at 21:26
which language are you using?
– gd1035
Jul 16 at 21:27
I'm working on python.
– eftshift0
Jul 16 at 21:31
2
Perhaps the built in Python function pow could be of use, it takes a third argument which is used to compute modulo: docs.python.org/3/library/functions.html#pow
– gd1035
Jul 16 at 21:49
 |Â
show 7 more comments
What is '^' operator?
– user58697
Jul 16 at 21:26
That's a power operation.
– eftshift0
Jul 16 at 21:26
which language are you using?
– gd1035
Jul 16 at 21:27
I'm working on python.
– eftshift0
Jul 16 at 21:31
2
Perhaps the built in Python function pow could be of use, it takes a third argument which is used to compute modulo: docs.python.org/3/library/functions.html#pow
– gd1035
Jul 16 at 21:49
What is '^' operator?
– user58697
Jul 16 at 21:26
What is '^' operator?
– user58697
Jul 16 at 21:26
That's a power operation.
– eftshift0
Jul 16 at 21:26
That's a power operation.
– eftshift0
Jul 16 at 21:26
which language are you using?
– gd1035
Jul 16 at 21:27
which language are you using?
– gd1035
Jul 16 at 21:27
I'm working on python.
– eftshift0
Jul 16 at 21:31
I'm working on python.
– eftshift0
Jul 16 at 21:31
2
2
Perhaps the built in Python function pow could be of use, it takes a third argument which is used to compute modulo: docs.python.org/3/library/functions.html#pow
– gd1035
Jul 16 at 21:49
Perhaps the built in Python function pow could be of use, it takes a third argument which is used to compute modulo: docs.python.org/3/library/functions.html#pow
– gd1035
Jul 16 at 21:49
 |Â
show 7 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
I will put my two comments in to an answer.
One option is to use the built-in Python function "pow()" and the documentation is found here: https://docs.python.org/3/library/functions.html#pow
Another option is to use the fact that: $(a cdot b) mod n = ((amod n)cdot(bmod n)mod n)$
So for your case you would have something like: $i^j mod k = (i mod k)^j mod k$
Thanks! But I'd like to get rid of the exponentiation if possible.
– eftshift0
Jul 16 at 22:05
I just tried using pow with the third parameter and I do see an improvement on performance. Some 2-4 percent. But as I grow the numbers that I'm using for all 3 elements, then the improvement dissipates.
– eftshift0
Jul 16 at 22:27
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
I will put my two comments in to an answer.
One option is to use the built-in Python function "pow()" and the documentation is found here: https://docs.python.org/3/library/functions.html#pow
Another option is to use the fact that: $(a cdot b) mod n = ((amod n)cdot(bmod n)mod n)$
So for your case you would have something like: $i^j mod k = (i mod k)^j mod k$
Thanks! But I'd like to get rid of the exponentiation if possible.
– eftshift0
Jul 16 at 22:05
I just tried using pow with the third parameter and I do see an improvement on performance. Some 2-4 percent. But as I grow the numbers that I'm using for all 3 elements, then the improvement dissipates.
– eftshift0
Jul 16 at 22:27
add a comment |Â
up vote
2
down vote
I will put my two comments in to an answer.
One option is to use the built-in Python function "pow()" and the documentation is found here: https://docs.python.org/3/library/functions.html#pow
Another option is to use the fact that: $(a cdot b) mod n = ((amod n)cdot(bmod n)mod n)$
So for your case you would have something like: $i^j mod k = (i mod k)^j mod k$
Thanks! But I'd like to get rid of the exponentiation if possible.
– eftshift0
Jul 16 at 22:05
I just tried using pow with the third parameter and I do see an improvement on performance. Some 2-4 percent. But as I grow the numbers that I'm using for all 3 elements, then the improvement dissipates.
– eftshift0
Jul 16 at 22:27
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I will put my two comments in to an answer.
One option is to use the built-in Python function "pow()" and the documentation is found here: https://docs.python.org/3/library/functions.html#pow
Another option is to use the fact that: $(a cdot b) mod n = ((amod n)cdot(bmod n)mod n)$
So for your case you would have something like: $i^j mod k = (i mod k)^j mod k$
I will put my two comments in to an answer.
One option is to use the built-in Python function "pow()" and the documentation is found here: https://docs.python.org/3/library/functions.html#pow
Another option is to use the fact that: $(a cdot b) mod n = ((amod n)cdot(bmod n)mod n)$
So for your case you would have something like: $i^j mod k = (i mod k)^j mod k$
answered Jul 16 at 22:01
gd1035
29319
29319
Thanks! But I'd like to get rid of the exponentiation if possible.
– eftshift0
Jul 16 at 22:05
I just tried using pow with the third parameter and I do see an improvement on performance. Some 2-4 percent. But as I grow the numbers that I'm using for all 3 elements, then the improvement dissipates.
– eftshift0
Jul 16 at 22:27
add a comment |Â
Thanks! But I'd like to get rid of the exponentiation if possible.
– eftshift0
Jul 16 at 22:05
I just tried using pow with the third parameter and I do see an improvement on performance. Some 2-4 percent. But as I grow the numbers that I'm using for all 3 elements, then the improvement dissipates.
– eftshift0
Jul 16 at 22:27
Thanks! But I'd like to get rid of the exponentiation if possible.
– eftshift0
Jul 16 at 22:05
Thanks! But I'd like to get rid of the exponentiation if possible.
– eftshift0
Jul 16 at 22:05
I just tried using pow with the third parameter and I do see an improvement on performance. Some 2-4 percent. But as I grow the numbers that I'm using for all 3 elements, then the improvement dissipates.
– eftshift0
Jul 16 at 22:27
I just tried using pow with the third parameter and I do see an improvement on performance. Some 2-4 percent. But as I grow the numbers that I'm using for all 3 elements, then the improvement dissipates.
– eftshift0
Jul 16 at 22:27
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2853871%2fsimplification-of-ijk%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
What is '^' operator?
– user58697
Jul 16 at 21:26
That's a power operation.
– eftshift0
Jul 16 at 21:26
which language are you using?
– gd1035
Jul 16 at 21:27
I'm working on python.
– eftshift0
Jul 16 at 21:31
2
Perhaps the built in Python function pow could be of use, it takes a third argument which is used to compute modulo: docs.python.org/3/library/functions.html#pow
– gd1035
Jul 16 at 21:49