2008-12-30, 22:24 | #1 |
Oct 2008
California
2^{2}×59 Posts |
coding midlet for TF
I finished the "powering algorithm" (described on the math page of GIMPS) , any suggestions for improvements in speed/size?
Code:
public boolean testFactor(int expo,int factor){ String n=Integer.toBinaryString(expo); //the binary representation long temp=1; do{ temp*=temp; //square temp<<=Integer.parseInt(n.substring(0,1)); //if the top bit is 1, multiply by 2 temp%=factor; //mod <the test factor> }while((n=n.substring(1)).length()>0); //remove the top bit, and continue if there is still more to do return (temp==1)?true:false; //if the final result is 1, then the test factor was a factor! } Last fiddled with by starrynte on 2008-12-30 at 22:25 |
2008-12-30, 22:31 | #2 |
"Robert Gerbicz"
Oct 2005
Hungary
588_{16} Posts |
Use sliding windows. (In gmp it is already implemented, see it's source.)
Last fiddled with by R. Gerbicz on 2008-12-30 at 22:32 |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Anyone know enough about coding to do this? | jrafanelli | Software | 2 | 2018-01-11 15:16 |
Python Coding Help? | kelzo | Programming | 3 | 2016-11-27 05:16 |
LLR Midlet | starrynte | Programming | 0 | 2010-12-14 06:17 |
Questions on coding my FFT&LLR implementation | nuggetprime | Programming | 56 | 2008-10-27 22:45 |
Coding Challenges | R.D. Silverman | Programming | 18 | 2005-08-09 13:14 |