Re: prime factorization


[Prev][Next][Index][Thread]

Re: prime factorization



 

Mark Baldi-Biek wrote:

Anyone have any code for prime factorization of an integer?
  Well, this is a really dumn one.  You'll have to enter a list P of primes, too. :0üK //initialize the prime factor counter
:Input "ENTER N ",N   //Enter the number to be factored
:1üI // initialize the prime counter
:While (P(I)ò÷N) // BIG LOOP while ith prime's square ÷ N
:  If (mod(N,P(I))==0) // If ith prime divides N
:  Then
:    1üJ // J will count to the largest power of p(I) that divides N
:    While (mod(N,(P(I))^(J+1))==0) // While a higher power divides N
:      J+1üJ // increment power
:    End // End nested while
:    K+1üK // increment number of distinct prime divisors.
:    KüdimL F    // F will be a list of prime power divisors p^k
:    (I,J)üF(K)  // with real part = p and imaginary part = k.
:    N/(P(I)^J)üN // Simply factor the remaining factor
:  End // End If
:  I+1üI // Increment prime counter
:End   // (BIG LOOP) End while since ith prime's square ù N
:ClLCD
:If (Nø1) // If there are proper divisors
:  Outpt(1,1,N) // This will be remaining (perhaps unfactored) factor
:For(M,1,K) // Run through list of prime divisors
:  Outpt(1+mod(M,9),1,P(real F(M))) // Fancy typesetting, eh?
:  Outpt(1+mod(M,9),2+int (log P(real F(M)))," ^ ") :  Outpt(1+mod(M,9),5+int (log P(real F(M))),imag F(M))
:  Pause // If there are lots of distinct prime factors
:End // End For loop
References: