Largest proper divisor of n: Difference between revisions

→‎{{header|REXX}}: added logic to a function to only use odd divisors for odd numbers.
(Realize in F#)
(→‎{{header|REXX}}: added logic to a function to only use odd divisors for odd numbers.)
Line 746:
 
=={{header|REXX}}==
Logic was added to the   '''LPDIV'''   function so that for   odd   numbers,   only odd divisors were used.
 
This addition made it about   '''75%'''   faster.
<lang rexx>/*REXX program finds the largest proper divisors of all numbers (up to a given limit). */
parse arg n cols . /*obtain optional argument from the CL.*/
Line 767 ⟶ 770:
/*──────────────────────────────────────────────────────────────────────────────────────*/
LPDIV: procedure; parse arg x; if x<4 then return 1 /*obtain X; test if X < 4. */
odd= x // 2; do kbeg= x % 2 by -1 /*startuse atBEG halfwayas pointthe andfirst decreasedivisor. */
if odd then if xbeg//k2==0 then returnbeg= kbeg - 1 /*NoIs X remainderodd? GotThen largestmake properBEG divodd.*/
end do k=beg by -1-odd /*kbegine at halfway point and decrease.*/
if x//k==0 then return 1 k /*theRemainder=0? number Got Xlargest proper is a primediv. */</lang>
end /*k*/
return 1 /*If we get here, then X is a prime.*/</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>