Primary Factorization Program (TI-84 +)

I am doing the first factorization on my calculator. It works great for smaller numbers, but shows strange behavior for 2 ^ n, n≥47. For a while it will be good, but then at some point the program disintegrates and after splashing out the primes 17 and 353 continues to work forever.

With my extremely limited programming knowledge, I suspect that the calculator cannot handle so many accurately and mess up the program.

Here's the code: (variables explained below outputs prime factors as A + Bi for prime factor A ^ B)

ClrHome
Disp "N=Number
Input "N: ",N
If N≥2 and not(fPart(N)):Then
    0→dim(ʟP)
    2→I
    0→R
    0→S
    Repeat N=1
        If not(fPart(N/I)):Then
            While not(fPart(N/I))
                N/I→N
                S+1→S
            End
            R+1→R
            I+Si→ʟP(R)
            0→S
        End
        I+1→I
    End
End
ʟP

      

#N: Number to be prime-factored (input)

#I: A prime factor

#R: Number of unique prime factors

#S: Exponent on prime factor

#ʟP: Prime factorization of N (output)

To reproduce this problem, run the program and enter any 2 ^ n for n≥47.

Does anyone know why this is happening?

+3


source to share


1 answer


Your hypothesis is correct. A valid data type in TI-Basic can store up to 44 bits of data ( source ). This can be proven using solve (command like this:

solve((X+1)-X,X,0

      

Whether it is executed as a program called a subroutine or executed from the main screen, this program / function outputs a large amount in the same range as your point of failure (which should never happen, because it X+1

will never be equal X

).



Also, I shortened the code a bit:

ClrHome
Prompt N
If N≥2 and not(fPart(N:Then
    0→dim(ʟP
    DelVar RDelVar S2→I
    Repeat N=1
        If not(fPart(N/I:Then
            While not(fPart(N/I
                N/I→N
                S+1→S
            End
            R+1→R
            I+Si→ʟP(R
            0→S
        End
        I+1→I
    End
End
ʟP

      

+2


source







All Articles