mersenneforum.org  

Go Back   mersenneforum.org > Extra Stuff > Programming

Reply
 
Thread Tools
Old 2008-12-30, 22:24   #1
starrynte
 
starrynte's Avatar
 
Oct 2008
California

22×59 Posts
Default 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!
}
(Still trying to work out the GUI and sieving)

Last fiddled with by starrynte on 2008-12-30 at 22:25
starrynte is offline   Reply With Quote
Old 2008-12-30, 22:31   #2
R. Gerbicz
 
R. Gerbicz's Avatar
 
"Robert Gerbicz"
Oct 2005
Hungary

58816 Posts
Default

Quote:
Originally Posted by starrynte View Post
I finished the "powering algorithm" (described on the math page of GIMPS) , any suggestions for improvements in speed/size?
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
R. Gerbicz is offline   Reply With Quote
Reply

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

All times are UTC. The time now is 06:22.

Tue Nov 24 06:22:30 UTC 2020 up 75 days, 3:33, 4 users, load averages: 1.76, 1.93, 2.03

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.