    1MODE 12
    2COLOUR 3
    3FOR d = 1 TO 2
    4   PRINT "BAsV Prgm ""calc.numberthy.a2p999//-0"",  4.09.95." ' "14.9.96.  multiplier, trap too big,  + Base 1000... 06.10.96, Mersenne nos."'
    5   NEXT d
    6
    7COLOUR 7
    8PRINT  ' "Program 2.4 (Allenby)" ' "To produce the decimal representations of the Mersenne numbers."
    9PRINT  "Typed in by Don McDonald, 63/5 Hutchison Rd, Welgton 2, N.Z.,  Ph: 64+4+389-6820."
   10
   11PRINT "#   :I found only trivial factors, (a-1) of:   a^858433-1."' "# "
   12PRINT "#   For what values of a? If indeed 858433 is prime then any factor"
   13PRINT "#   of a^858433-1 is either a-1 or congruent to 1 mod 2*858433. Did "
   14PRINT "#   you check for factors of this form?"
   15PRINT "Don.  (No xx).  I should learn."
   16PRINT  '"E.g. 2^8191 - 1 =  2* (2^9)^910-1. composite."'
   54PRINT  "prog 3.3," ' "  to check possible factors ( up to 2^32-1) of Fermat or Mersenne numbers."
   55PRINT "2^67-1  =  193,707,721 * 761,838,257,287.  FN Cole, 1903."
   56PRINT"2^15-1 = 32767 = 151 x 217.    10^17-1 =  2,071,723x 5363222357x9."
   57PRINT"2^39-1 = 647,089 x 849,583  "
   58PRINT"2^43-1 = 2,099,863 x 4,188,889  "
   59PRINT"...   2^45-1 ??  "
   60PRINT"2^47-1 = 10,610,063 x 13,264,529 " 
   16DIM F(3000)     ,  Q(3000)
   17
   18N = 0
   19a = 0
   20off = 0
   22
   23      INPUT' "text expression "; t$
   24
   23INPUT'' "enter N$ (prime.. exponent of M_p = 2^p - 1), 0 quit" ; N$
   24   N = EVAL N$  :  PRINT  N$ " = "; N
   24IF N < 1 THEN PRINT "calc.numberthy.a2p-0  e . n. d.":  END
   25
   26F() = (0)
   27Q() = (0)
   28F(1) = 1 : 
   29NF = 1
   30
   31INPUT' "enter base expression, (e.g. 2, 10, etc.) a$ = ";a$
   32   REM   IF a$ = "0" TH. PRINT "Program ""calc.numberThy.a2p999""  e . n . d.":  END
   32   a = EVAL a$  :  PRINT a$ " = "; a
   33   INPUT' "Enter multiplier, F(1), default 1."; F$
   34        IF F$ = "" THEN F$ = "1"
   34   F(1) = EVAL F$  :  PRINT F$ " = "; F(1)
   32INPUT "enter offset, 0 goes to  -1  etc. = ";off
   33           IF off = 0 THEN
   34              PRINT"off = -1  Return (Y) or  Hit Nn?"
   35              IF INSTR("Nn",GET$) THEN PRINT  "No." ' : INPUT"offset "; off : ELSE off = -1
   36              ENDIF
   37           PRINT ' "offset = "; off   
   38           PRINT ' "dec. digits order "; N*LOG(a)  '
   39           IF N*LOG(a) > 2999 THEN PRINT "DIM 2999 not big enough." : STOP
   33FOR I = 1 TO N
   34   FOR J = 1 TO NF
   35      F(J) = F(J)*a
   36      NEXT J
   37
   38   FOR J = 1 TO NF
   39      F(J+1) = F(J+1) + F(J) DIV 1000
   40      F(J) = F(J) MOD 1000
   41      NEXT J
   42
   43   IF F(NF+1) <> 0 THEN NF = NF +1
   44   NEXT I
   45
   46F(1) = F(1) + off
   47
   48REM to display the numbers the array is printed out in reverse since the first position in the array contains the units etc.
   49
   50FOR K = NF TO 1 STEP -1
   51   PRINT  ; F(K) ",";
   52   NEXT K
   53   PRINT  "  base 1,000."
   54
   56REM D contains a possible factor.
   57   D$ = "1" : d$ = "0"
   58   D =  1  :  d =  2
   21ON ERROR REPORT  :  PRINT CHR$(7)"  at erl. "; ERL  "  t$ = "t$ '"N = "; N  "  a = ";a  "  F = "F$ "  off = "; off
   57
   58   INPUT "enter possible factor, Return  = 1, 0= RUN Again. D = "; D$
   59        IF D$ = "0" THEN RUN
   59   IF D$ = "" THEN D$ = "1"
   60   D = EVAL(D$)  :  PRINT D$ " = "; D
   59   INPUT "enter step in factor each time, return = 2, 0 quit.  d = "; d$
   60        IF d$="" THEN d = 2  ELSE d = EVAL(d$)
   61        :  PRINT d$ " = "; d
   62        IF d = 0 THEN STOP
   63
   64   INPUT ' "start at minimum (MODified 21.02.98.) ";d1
   65   D = (d1 DIV d)*d + D
   66   REM  REP. D += d  : UNTIL D >= d1
   67
   60REPEAT
   61   n = 0
   62   PROCdivide
   63   D += d
   64   UNTIL D < 1 OR d = 0
   65
   66PRINT "E.N.D."  :  END
   67
   68DEF PROCdivide
   69FOR I = NF TO 1 STEP -1
   70   n = n *1000 + F(I)
   71
   72   IF ABS n >= 2^31 THEN ERROR 17,"REM trap Too Big, try a2p0. n.b. 2^67-1."
   71   Q(I) = INT(n/D)
   72   n = n- INT(n/D)*D
   73   NEXT I
   74
   75IF n = 0 THEN
   76   PRINT 'CHR$(7)  D; "  cofactor = ";
   77   FOR I = NF TO 1 STEP -1
   78       REM  ?? PRINT  ; RIGHT$("000"+STR$(Q(I)),3)",";  :
   79            IF ABS Q(I) < 10 PRINT ; "00";  ELSE IF ABS Q(I) < 100 PRINT ; "0";
   80            PRINT  ; Q(I)"," ;
   81
   79      NEXT I
   80
   81   PRINT  n ; " contin";GET$
   82   PRINT  "GOTO next operation as factor is found."
   83   ELSE
   84   PRINT ;  D ", ";  : REM  "  is not a factor."
   85   IF POS > 56 THEN PRINT " not fact."
   86   ENDIF
   87
   88REM  Set up the next possible factor.
   89ENDPROC