Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Can /prog/ please comment on my code?

Name: Anonymous 2010-08-02 19:20


class prob3{
   
    static long BigBossPrimeOne;
   
    public static void primeFactor(long n){
    boolean prime = true;
    long n1=0;
    long n2=0;
    for(long i=2;(i<=(n/2))&&(prime!=false);i++)
        if ((n%i)==0){
        prime = false;
        n1=i;
        n2=n/i;   
        }   
    if ((prime==true)&&(n>BigBossPrimeOne))
        BigBossPrimeOne = n;
   
    if (prime==false){
        primeFactor(n1);
        primeFactor(n2);
        }            
    }

    public static void main(String args[]){
 
    primeFactor(600851475143L);
    System.out.println(BigBossPrimeOne);
    }

}


I'm just doing the Euler thing to pass the time and I thought why not post this on /prog/ for some insight.

Using the Java language.

Feel free to give me any advice.

Thanks!

Please don't mind the presentation. It's the first time using Emacs and I was under the clock (did this in 15 minutes).

Name: Anonymous 2010-08-03 6:51

>>37 Ok, its now converted to Purebasic4.5 and added a CPU speed for speedstep/dynamic mhz detection.

Procedure GetCycleCount():  !RDTSC  
::ProcedureReturn:EndProcedure;
Procedure CPUSPEED(): Protected A.q,B.q: time_fix2:A = GetCycleCount(): Sleep_(100): B = GetCycleCount():While (B-A)<1: Goto time_fix2:Wend: ProcedureReturn (B-A)/100000:EndProcedure;
Define.q n,i=5,s=2,starttime,endtime:OpenConsole():If CountProgramParameters():n.q=Val(ProgramParameter()):Else:n.q=600851475143:EndIf:starttime=GetCycleCount():
While n<>2 And (Not (n%2)) :n=n>>1::Wend:While n<>3 And (Not (n%3)) :n=n/3::Wend:
While ((i*i)<=n) :While n<>i And (Not (n%i)) :n=n/i::Wend:: s=s!2: i=i+s+2:Wend:endtime=GetCycleCount()-starttime:
PrintN(Str(n)):PrintN("Elapsed:"+Str(endtime)+" cycles at speed "+Str(CPUSPEED())+" MHZ"):

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List