How to resolve the algorithm Radical of an integer step by step in the MAD programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Radical of an integer step by step in the MAD programming language
Table of Contents
Problem Statement
The radical of a positive integer is defined as the product of its distinct prime factors.
Although the integer 1 has no prime factors, its radical is regarded as 1 by convention.
The radical of 504 = 2³ x 3² x 7 is: 2 x 3 x 7 = 42.
- Find and show on this page the radicals of the first 50 positive integers.
- Find and show the radicals of the integers: 99999, 499999 and 999999.
- By considering their radicals, show the distribution of the first one million positive integers by numbers of distinct prime factors (hint: the maximum number of distinct factors is 7).
By (preferably) using an independent method, calculate the number of primes and the number of powers of primes less than or equal to one million and hence check that your answer in 3. above for numbers with one distinct prime is correct.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Radical of an integer step by step in the MAD programming language
Source code in the mad programming language
NORMAL MODE IS INTEGER
INTERNAL FUNCTION(A,B)
ENTRY TO REM.
FUNCTION RETURN A-A/B*B
END OF FUNCTION
INTERNAL FUNCTION(NN)
ENTRY TO RADIC.
KN = NN
DPF = 0
RAD = 1
WHENEVER KN.E.0, FUNCTION RETURN 0
WHENEVER REM.(KN,2).E.0
DPF = 1
RAD = 2
THROUGH DIV2, FOR KN=KN, 0, REM.(KN,2).NE.0
DIV2 KN = KN / 2
END OF CONDITIONAL
THROUGH ODD, FOR FAC=3, 2, FAC.G.KN
WHENEVER REM.(KN,FAC).E.0
DPF = DPF + 1
RAD = RAD * FAC
THROUGH DIVP, FOR KN=KN, 0, REM.(KN,FAC).NE.0
DIVP KN = KN / FAC
END OF CONDITIONAL
ODD CONTINUE
FUNCTION RETURN RAD
END OF FUNCTION
R PRINT RADICALS FOR 1..50
VECTOR VALUES RADLIN = $10(I5)*$
PRINT COMMENT $ RADICALS OF 1 TO 50$
THROUGH RADL, FOR L=0, 10, L.GE.50
RADL PRINT FORMAT RADLIN,
0 RADIC.(L+1),RADIC.(L+2),RADIC.(L+3),RADIC.(L+4),
1 RADIC.(L+5),RADIC.(L+6),RADIC.(L+7),RADIC.(L+8),
2 RADIC.(L+9),RADIC.(L+10)
R PRINT RADICALS OF TASK NUMBERS
PRINT COMMENT $ $
VECTOR VALUES RADNUM = $14HTHE RADICAL OF,I7,S1,2HIS,I7*$
THROUGH RADN, FOR VALUES OF N = 99999, 499999, 999999
RADN PRINT FORMAT RADNUM,N,RADIC.(N)
R FIND DISTRIBUTION
PRINT COMMENT $ $
DIMENSION DIST(8)
THROUGH ZERO, FOR D = 0, 1, D.G.7
ZERO DIST(D) = 0
THROUGH CNTDST, FOR N = 1, 1, N.G.1000000
RADIC.(N)
CNTDST DIST(DPF) = DIST(DPF) + 1
PRINT COMMENT $ DISTRIBUTION OF RADICALS$
VECTOR VALUES DISTLN = $I1,2H: ,I8*$
THROUGH SHWDST, FOR D = 0, 1, D.G.7
SHWDST PRINT FORMAT DISTLN,D,DIST(D)
END OF PROGRAM
You may also check:How to resolve the algorithm Partition function P step by step in the 11l programming language
You may also check:How to resolve the algorithm 24 game step by step in the Simula programming language
You may also check:How to resolve the algorithm File modification time step by step in the Raku programming language
You may also check:How to resolve the algorithm Giuga numbers step by step in the 11l programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the PL/I programming language