How to resolve the algorithm Cullen and Woodall numbers step by step in the BASIC programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Cullen and Woodall numbers step by step in the BASIC programming language
Table of Contents
Problem Statement
A Cullen number is a number of the form n × 2n + 1 where n is a natural number. A Woodall number is very similar. It is a number of the form n × 2n - 1 where n is a natural number. So for each n the associated Cullen number and Woodall number differ by 2. Woodall numbers are sometimes referred to as Riesel numbers or Cullen numbers of the second kind.
Cullen primes are Cullen numbers that are prime. Similarly, Woodall primes are Woodall numbers that are prime. It is common to list the Cullen and Woodall primes by the value of n rather than the full evaluated expression. They tend to get very large very quickly. For example, the third Cullen prime, n == 4713, has 1423 digits when evaluated.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Cullen and Woodall numbers step by step in the BASIC programming language
Source code in the basic programming language
10 REM Cullen and Woodall numbers
20 HOME : REM 20 CLS for Chipmunk Basic
30 PRINT "First 20 Cullen numbers:"
40 FOR n = 1 TO 20
50 num = n*(2^n)+1
60 PRINT INT(num);" ";
70 NEXT
80 PRINT : PRINT
90 PRINT "First 20 Woodall numbers:"
100 FOR n = 1 TO 20
110 num = n*(2^n)-1
120 PRINT INT(num);" ";
130 NEXT n
140 END
print "First 20 Cullen numbers:"
for n = 1 to 20
num = n * (2^n)+1
print int(num); " ";
next
print : print
print "First 20 Woodall numbers:"
for n = 1 to 20
num = n * (2^n)-1
print int(num); " ";
next n
end
10 REM Cullen and Woodall numbers
20 CLS : REM 20 HOME for Applesoft BASIC
30 PRINT "First 20 Cullen numbers:"
40 FOR n = 1 TO 20
50 num = n*(2^n)+1
60 PRINT INT(num);" ";
70 NEXT
80 PRINT : PRINT
90 PRINT "First 20 Woodall numbers:"
100 FOR n = 1 TO 20
110 num = n*(2^n)-1
120 PRINT INT(num);" ";
130 NEXT n
140 END
Dim As Uinteger n, num
Print "First 20 Cullen numbers:"
For n = 1 To 20
num = n * (2^n)+1
Print num; " ";
Next
Print !"\n\nFirst 20 Woodall numbers:"
For n = 1 To 20
num = n * (2^n)-1
Print num; " ";
Next n
Sleep
Public Sub Main()
Dim n, num As Integer
Print "First 20 Cullen numbers:"
For n = 1 To 20
num = n * (2 ^ n) + 1
Print num; " ";
Next
Print "\n\nFirst 20 Woodall numbers:"
For n = 1 To 20
num = n * (2 ^ n) - 1
Print num; " ";
Next
End
OpenConsole()
PrintN("First 20 Cullen numbers:")
For n.i = 1 To 20
num = n * Pow(2, n)+1
Print(Str(num) + " ")
Next
PrintN(#CRLF$ + "First 20 Woodall numbers:")
For n.i = 1 To 20
num = n * Pow(2, n)-1
Print(Str(num) + " ")
Next n
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
CloseConsole()
DIM num AS LONG ''comment this line for True BASIC
PRINT "First 20 Cullen numbers:"
FOR n = 1 TO 20
LET num = n * (2 ^ n) + 1
PRINT num;
NEXT n
PRINT
PRINT
PRINT "First 20 Woodall numbers:"
FOR n = 1 TO 20
LET num = n * (2 ^ n) - 1
PRINT num;
NEXT n
END
print "First 20 Cullen numbers:"
for n = 1 to 20
num = n * (2^n)+1
print int(num); " ";
next
print : print
print "First 20 Woodall numbers:"
for n = 1 to 20
num = n * (2^n)-1
print int(num); " ";
next n
end
REM Rosetta Code problem: https://rosettacode.org/wiki/Cullen_and_Woodall_numbers
REM by Jjuanhdez, 03/2023
REM TinyBasic does not support values greater than 32767
PRINT "First 11 Cullen numbers:"
LET N = 0
LET I = 1
10 IF I = 12 THEN GOTO 20
GOSUB 50
LET N = (I*R) +1
PRINT N, " "
LET I = I+1
GOTO 10
20 PRINT ""
PRINT "First 11 Woodall numbers:"
LET I = 1
30 IF I = 12 THEN GOTO 40
GOSUB 50
LET N = (I*R) -1
PRINT N, " "
LET I = I+1
GOTO 30
40 END
50 REM Exponent calculation
LET A = 2
LET B = I
LET X = 1
LET R = 2
60 IF X >= B THEN RETURN
LET T = R
IF R < A THEN LET R = A*A
IF T < A THEN GOTO 70
IF R >= A THEN LET R = R*A
70 LET X = X+1
GOTO 60
REM DIM num AS LONG !uncomment this line for QBasic
PRINT "First 20 Cullen numbers:"
FOR n = 1 TO 20
LET num = n * (2 ^ n) + 1
PRINT num;
NEXT n
PRINT
PRINT
PRINT "First 20 Woodall numbers:"
FOR n = 1 TO 20
LET num = n * (2 ^ n) - 1
PRINT num;
NEXT n
END
PROGRAM "progname"
VERSION "0.0000"
IMPORT "xma"
DECLARE FUNCTION Entry ()
FUNCTION Entry ()
PRINT "First 20 Cullen numbers:"
FOR n = 1 TO 20
num! = n * POWER (2, n) + 1
PRINT num!;
NEXT n
PRINT
PRINT
PRINT "First 20 Woodall numbers:"
FOR n = 1 TO 20
num! = n * POWER (2, n) - 1
PRINT num!;
NEXT n
END FUNCTION
END PROGRAM
print "First 20 Cullen numbers:"
for n = 1 to 20
num = n * (2^n)+1
print num, " ";
next
print "\n\nFirst 20 Woodall numbers:"
for n = 1 to 20
num = n * (2^n)-1
print num, " ";
next n
print
end
You may also check:How to resolve the algorithm Zebra puzzle step by step in the Erlang programming language
You may also check:How to resolve the algorithm Matrix transposition step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Déjà Vu programming language
You may also check:How to resolve the algorithm Price fraction step by step in the Ursala programming language
You may also check:How to resolve the algorithm Sequence of non-squares step by step in the HicEst programming language