|  | 
|  | 
| back to board | How find 24^(-1) mod p Posted by svr  22 Sep 2007 22:32One method uses formula a4=(t1^4-6*t1^2*t2+3*t2^2+8*t1*t3-6*t4)/24 mod pFor it we must find previously 24^(-1) mod p
 But it needs in loop with ~ p=10^9 iterations
 May this calculation lead to TL before main program?
Re: How find 24^(-1) mod p Why can't we use extended euclid?Re: How find 24^(-1) mod p or use fermat little theorem
 a^(p-1) = 1 (mod p)
 a^(p-2).a = 1 (mod p)
 
 so a^(-1) = a^(p-2) :)
Re: How find 24^(-1) mod p // O(a)inline int inv(int a)
 {
 for (int i = 1; ; i++)
 {
 int64 b = (int64) P * i + 1;
 if (b % a == 0)
 return int(b / a);
 }
 return 0;
 }
Re: How find 24^(-1) mod p Posted by svr  30 Sep 2007 09:39Best advise was extended evclidI could apply it during the context.
 But 1560 wuild bettter to solve in Java using BigInt
 We simply use /24 at the end and avoid many %p operations.
Re: How find 24^(-1) mod p a/b mod p = a*b^-1 mod p = a*b^(-1 mod p-1) mod p = a*b^(p-2) mod p. b^(p-2) can be precomputed using logarithmic powering. I needed only divisors 2, 6 and 24. | 
 | 
|