Quick Math Question for you guru's

MrScott81

Golden Member
Aug 31, 2001
1,891
0
76
I need to know a good way to compute the following without actually doing the math. I know there is a cool trick you can use without having to compute values, but I can't remember!
(x^y) mod m

This is easy for small numbers, but for stuff like 20^105 % 48 it becomes ugly.
Can someone help? Thanks!
Scott
 

Gibson486

Lifer
Aug 9, 2000
18,378
2
0
Originally posted by: MrScott81
I need to know a good way to compute the following without actually doing the math. I know there is a cool trick you can use without having to compute values, but I can't remember!
(x^y) mod m

This is easy for small numbers, but for stuff like 20^105 % 48 it becomes ugly.
Can someone help? Thanks!
Scott

so, you want the first few digits of the remainder?
 

MrScott81

Golden Member
Aug 31, 2001
1,891
0
76
Originally posted by: Gibson486
Originally posted by: MrScott81
I need to know a good way to compute the following without actually doing the math. I know there is a cool trick you can use without having to compute values, but I can't remember!
(x^y) mod m

This is easy for small numbers, but for stuff like 20^105 % 48 it becomes ugly.
Can someone help? Thanks!
Scott

so, you want the first few digits of the remainder?

No I need to compute x to the power of y modulo m.


Thanks, but this is for a computer program, so I can't hardcode stuff :)

Anyone else?? I know I learned this before!
 

DAGTA

Diamond Member
Oct 9, 1999
8,172
1
0
Are you doing something dealing with encryption? Either way, many encryption algorithms use math similar to this and have very efficient algorithms for said math. It's been a few years so I don't recall the names of the specific algorithm but I know I used it while working with the Jacobi algorithm, so mabye a search on Jacobi will turn up something helpful for you.
 

TuxDave

Lifer
Oct 8, 2002
10,571
3
71
Here's one identity... dunno what you can do with this.

x^y%m

let k = x%m

k^y%m=x^y%m
 

MrScott81

Golden Member
Aug 31, 2001
1,891
0
76
yep, this is for encryption.....
thanks TuxDave, that's exactly the formula I couldn't remember!!