Here is a code I wrote a long time ago, back when I was fresh to the programming world. I'm not exactly proud of it, since it is inefficient and may fail with some equations, but it seems to work adequately and can distinguish prime factors.

ClrHome

"?→Str1

Disp "AX2+BX+C=0

Prompt A,B,C

If A<0

Then

‾A→A

‾B→B

‾C→C

End

gcd(A,abs(B

gcd(Ans,abs(C→V

A/Ans→A

B/V→B

C/V→C

For(D,A,1,‾1

If not(fPart(A/D

Then

For(E,abs(C),1,‾1

If not(fPart(C/E

Then

A/D→F

abs(C/E→G

If DAns+FE=B and EG=C

"1D1E1F1G→Str1

If DG-FE=B and ‾EG=C

"1D‾E1F1G→Str1

If FE‾DG=B and ‾EG=C

"1D1E1F‾G→Str1

If ‾DG-FE=B and EG=C

"1D‾E1F‾G→Str1

If DE+FG=B and EG=C

"1D1G1F1E→Str1

If DE-FG=B and ‾EG=C

"1D‾G1F1E→Str1

If FG-DE=B and ‾EG=C

"1D1G1F‾E→Str1

If ‾DE-FG=B and EG=C

"1D‾G1F‾E→Str1

If Str1≠"?

Then

ClrHome

Disp "(AX+B)(CX+D)=0

For(H,1,7,2

Disp expr(sub(Str1,H,2

End

Disp "FACTOR OUT

Output(7,2,V

Return

End

End

End

End

End

ClrHome

Disp "PRIME

Disp "FACTOR OUT

Output(3,2,V

You can make a better code simply by using the quadratic formula to find the roots. If the roots are imaginary or irrational, then it is prime. Otherwise, the thing is factorable. Even a root like (x-0.5) can be converted into (2x-1) with calculator logic.