In the last issue we challenged you to write a slick program to find the factors of a number and to identify prime numbers.

Here is one possible solution. Note N<1.7x1038

10 INPUT "TYPE A POSITIVE INTEGER AND PRESS ENTER"; N
20 LET T=2
30 PRINT "1"
N 40 FOR J=2 TO SQR(N)
50 IF INT(N/J) = N/J THEN LET T=T+2:PRINT J, N/J
60 NEXT J
70 IF T>2 THEN PRINT N "IS NOT A PRIME" ELSE PRINT N "IS A PRIME"

QBASIC has another important mathematical function: MOD.

Here is how it works: 64 MOD 9=1 as 64=7*9+1. So x MOD y gives the remainder when x is divided by y.

In BASIC you can define a MOD function using the following command.

DEF FNM(X)=X-INT(X/J)*J

1. Change line 50 and find factors using MOD function.

2. Change the program so that it prints only prime factors of N.