Count in factors: Difference between revisions

Add NetRexx implementation
m (→‎{{header|REXX}}: it's -> its ( they all do it :-( ))
(Add NetRexx implementation)
Line 1,122:
Print[Row[Riffle[Flatten[Map[Apply[ConstantArray, #] &, FactorInteger[n]]],"*"]]];
n++]</lang>
 
=={{header|NetRexx}}==
{{trans|Java}}
<lang NetRexx>/* NetRexx */
options replace format comments java crossref symbols nobinary
 
runSample(arg)
return
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method factor(val) public static
rv = 1
if val > 1 then do
rv = ''
loop n_ = val until n_ = 1
parse checkFactor(2, n_, rv) n_ rv
if n_ = 1 then leave n_
parse checkFactor(3, n_, rv) n_ rv
if n_ = 1 then leave n_
loop m_ = 5 to n_ by 2
if m_ // 3 = 0 then iterate m_
parse checkFactor(m_, n_, rv) n_ rv
if n_ = 1 then leave m_
end m_
end n_
end
return rv
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method checkFactor(mult = long, n_ = long, fac) private static binary
msym = 'x'
loop while n_ // mult = 0
fac = fac msym mult
n_ = n_ % mult
end
fac = (fac.strip).strip('l', msym).space
return n_ fac
 
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method runSample(arg) private static
-- input is a list of pairs of numbers - no checking is done
if arg = '' then arg = '1 11 89 101 1000 1020 10000 10010'
loop while arg \= ''
parse arg lv rv arg
say
say '-'.copies(60)
say lv.right(8) 'to' rv
say '-'.copies(60)
loop fv = lv to rv
fac = factor(fv)
pv = ''
if fac.words = 1 & fac \== 1 then pv = '<prime>'
say fv.right(8) '=' fac pv
end fv
end
return
</lang>
{{out}}
<pre style="height: 30em;overflow: scroll; font-size: smaller;">
------------------------------------------------------------
1 to 11
------------------------------------------------------------
1 = 1
2 = 2 <prime>
3 = 3 <prime>
4 = 2 x 2
5 = 5 <prime>
6 = 2 x 3
7 = 7 <prime>
8 = 2 x 2 x 2
9 = 3 x 3
10 = 2 x 5
11 = 11 <prime>
 
------------------------------------------------------------
89 to 101
------------------------------------------------------------
89 = 89 <prime>
90 = 2 x 3 x 3 x 5
91 = 7 x 13
92 = 2 x 2 x 23
93 = 3 x 31
94 = 2 x 47
95 = 5 x 19
96 = 2 x 2 x 2 x 2 x 2 x 3
97 = 97 <prime>
98 = 2 x 7 x 7
99 = 3 x 3 x 11
100 = 2 x 2 x 5 x 5
101 = 101 <prime>
 
------------------------------------------------------------
1000 to 1020
------------------------------------------------------------
1000 = 2 x 2 x 2 x 5 x 5 x 5
1001 = 7 x 11 x 13
1002 = 2 x 3 x 167
1003 = 17 x 59
1004 = 2 x 2 x 251
1005 = 3 x 5 x 67
1006 = 2 x 503
1007 = 19 x 53
1008 = 2 x 2 x 2 x 2 x 3 x 3 x 7
1009 = 1009 <prime>
1010 = 2 x 5 x 101
1011 = 3 x 337
1012 = 2 x 2 x 11 x 23
1013 = 1013 <prime>
1014 = 2 x 3 x 13 x 13
1015 = 5 x 7 x 29
1016 = 2 x 2 x 2 x 127
1017 = 3 x 3 x 113
1018 = 2 x 509
1019 = 1019 <prime>
1020 = 2 x 2 x 3 x 5 x 17
 
------------------------------------------------------------
10000 to 10010
------------------------------------------------------------
10000 = 2 x 2 x 2 x 2 x 5 x 5 x 5 x 5
10001 = 73 x 137
10002 = 2 x 3 x 1667
10003 = 7 x 1429
10004 = 2 x 2 x 41 x 61
10005 = 3 x 5 x 23 x 29
10006 = 2 x 5003
10007 = 10007 <prime>
10008 = 2 x 2 x 2 x 3 x 3 x 139
10009 = 10009 <prime>
10010 = 2 x 5 x 7 x 11 x 13
</pre>
 
=={{header|Objeck}}==
Anonymous user