Jump to content

Tau number: Difference between revisions

2,686 bytes removed ,  4 days ago
(PascalABC.NET)
(→‎{{header|REXX}}: overhauled)
Line 2,848:
 
=={{header|REXX}}==
simplified,
<syntaxhighlight lang="rexx">/*REXX pgm displays N tau numbers, an integer divisible by the # of its divisors). */
made ooRexx compatible,
parse arg n cols . /*obtain optional argument from the CL.*/
corrected for tau of squares,
if n=='' | n=="," then n= 100 /*Not specified? Then use the default.*/
corrected for a range with fewer than cols numbers.
if cols=='' | cols=="," then cols= 10 /*Not specified? Then use the default.*/
w<syntaxhighlight lang="rexx">/* max(8,REXX length(n)program )counts the number of divisors (tau,cr sigma_0) /*W: used to align 1st output column. */
/* for a range of numbers end /* ___ */
@tau= ' the first ' commas(n) " tau numbers " /*the title of the tau numbers table. */
parseParse argArg nlo hi cols . /*obtain optional argument from the CL.*/
say ' index │'center(@tau, 1 + cols*(w+1) ) /*display the title of the output table*/
ifIf nlo=='' | nlo=="',"' Then then nlo= 1001 /*Not specified? Then use the default.*/
say '───────┼'center("" , 1 + cols*(w+1), '─') /* " " header " " " " */
ifIf cols hi=='' | cols hi=="',"' Then then colshi= 10 lo+100-1 /*Not specified? Then use the default.*/
idx= 1; #= 0; $= /*idx: line; #: tau numbers; $: #s */
If cols=='' do j=1 untilThen #cols==n20 /* " " /*search for " N " tau numbers" " */
w=2+(hi>45359) if j//tau(j) \==0 then iterate /*Is this a tau number? No,/* width of columns tau(4mns5360)=100 then skip.*/
Say 'The number of divisors (tau) from' lo 'to' hi '(inclusive):'
#= # + 1 /*bump the count of tau numbers found. */
Say ''
$= $ right( commas(j), w) /*add a tau number to the output list. */
Say '-number' center(' tau (number of divisors) ',cols*(w+1)+1,'-')
if #//cols\==0 then iterate /*Not a multiple of cols? Don't show. */
line=''
say center(idx, 7)'│' substr($, 2) /*display partial list to the terminal.*/
c=0
idx= idx + cols; $= /*bump idx by number of cols; nullify $*/
index=lo
end /*j*/
Do j=lo To hi
 
c=c+1
if $\=='' then say center(idx, 7)"│" substr($, 2) /*possible display residual output.*/
$line= $ line right( commastau(j), w) /* add a tau number to the output listline. */
say '───────┴'center("" , 1 + cols*(w+1), '─')
exit 0 If c//cols=0 Then Do /* line has cols numbers /*stick a fork in it, we're all done. */
Say center(index,7) line
/*──────────────────────────────────────────────────────────────────────────────────────*/
line=''
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
cnt=0
/*──────────────────────────────────────────────────────────────────────────────────────*/
Index=index+cols
tau: procedure; parse arg x 1 y /*X and $ are both set from the arg.*/
End
if x<6 then return 2 + (x==4) - (x==1) /*some low #s should be handled special*/
endEnd /*j*/
odd= x // 2 /*check if X is odd (remainder of 1).*/
If line\=='' Then
if odd then do; #= 2; end /*Odd? Assume divisor count of 2. */
Say center(index,7) line else do; #= 4; y= x % 2; end /*Even?there any residuals left To display " " " " 4. ? */
Exit 0 /*stick a fork in it, we're all done. /* [↑] start with known number of divs*/
/*---------------------------------------------------------------------------------*/
do j=3 for x%2-3 by 1+odd while j<y /*for odd number, skip even numbers. */
tau: Procedure
if x//j==0 then do /*if no remainder, then found a divisor*/
Parse Arg x
#= # + 2; y= x % j /*bump # of divisors; calculate limit.*/
If x<6 Then if j>=y then do; #= # -/* 1;some low numbers leave;are handled special end /*reached limit?*/
Return 2+(x==4)-(x==1)
end /* ___ */
tau=0
else if j*j>x then leave /*only divide up to √ x */
odd=x//2
end /*j*/ /* [↑] this form of DO loop is faster.*/
Do j=1 by 1 While j*j<x
return #</syntaxhighlight>
ifIf odd & thenj//2=0 do;Then #= 2; end /*Odd? even j can't Assumebe a divisor count of an 2. odd x*/
Iterate
ifIf x//j==0 thenThen do /* if no remainder, then found a divisor*/
odd tau=tau+2 x // 2 /* bump n of divisors /*check if X is odd (remainder of 1).*/
End
idx If j*j=x 1;Then #= 0; /* x is a square $= /*idx: line; #: tau numbers; $: #s */
tau=tau+1 else if j*j>x then leave /*only divideits uproot tois a divisor x */
Return return #tau</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input:}}
<pre>
The number of divisors (tau) from 1 to 100 (inclusive):
index │ the first 100 tau numbers
 
───────┼───────────────────────────────────────────────────────────────────────────────────────────
-number ----------------- tau (number of divisors) ------------------
1 │ 1 2 8 9 12 18 24 36 40 56
11 1 1 2 60 2 3 2 724 2 4 3 80 4 2 6 842 4 4 5 88 2 6 2 96 104 108 128 1326
21 4 4 136 2 8 3 152 4 4 6 156 2 8 2 180 6 4 4 184 4 9 2 204 4 4 225 228 232 2408
3141 2 8 248 2 6 6 252 4 2 10 2763 6 4 2886 2 8 2964 8 4 3284 2 344 348 360 37212
4161 2 4 376 6 7 4 384 8 2 6 396 4 8 2 42412 2 4 4416 6 4 4448 2 448 450 468 47210
5181 5 4 480 2 12 4 4884 4 8 4922 12 4 6 504 4 4 4 51612 2 6 5366 560 564 568 5849
61 │ 600 612 625 632 636 640 664 672 684 708
71 │ 712 720 732 776 792 804 808 824 828 852
81 │ 856 864 872 876 880 882 896 904 936 948
91 │ 972 996 1,016 1,040 1,044 1,048 1,056 1,068 1,089 1,096
───────┴───────────────────────────────────────────────────────────────────────────────────────────
</pre>
 
2,299

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.