Multiplicatively perfect numbers: Difference between revisions

J
m (→‎{{header|Phix}}: rewrote/added stretch goal)
(J)
Line 135:
{{out}}
<pre>Similar to Ring entry.</pre>
 
=={{header|J}}==
 
Implementation:
 
<syntaxhighlight lang=J>factors=: [: /:~@, */&>@{@((^ i.@>:)&.>/)@q:~&__
isMPerfect=: *: = */@(factors ::_:)"0</syntaxhighlight>
 
Task example:
 
<syntaxhighlight lang=J> #(#~ isMPerfect) i.500
150
10 15$(#~ isMPerfect) i.500
1 6 8 10 14 15 21 22 26 27 33 34 35 38 39
46 51 55 57 58 62 65 69 74 77 82 85 86 87 91
93 94 95 106 111 115 118 119 122 123 125 129 133 134 141
142 143 145 146 155 158 159 161 166 177 178 183 185 187 194
201 202 203 205 206 209 213 214 215 217 218 219 221 226 235
237 247 249 253 254 259 262 265 267 274 278 287 291 295 298
299 301 302 303 305 309 314 319 321 323 326 327 329 334 335
339 341 343 346 355 358 362 365 371 377 381 382 386 391 393
394 395 398 403 407 411 413 415 417 422 427 437 445 446 447
451 453 454 458 466 469 471 473 478 481 482 485 489 493 497</syntaxhighlight>
 
For the stretch goal, we need to determine the number of semi-primes, given the number of multiplicatively perfect numbers less than N:
 
<syntaxhighlight lang=J>adjSemiPrime=: _1 + %: -&(p:inv) 3&%:</syntaxhighlight>
 
Thus (first number is count of multiplicatively perfect numbers, second is count of semiprimes:
 
<syntaxhighlight lang=J> {{ (, (adjSemiPrime y)+]) +/isMPerfect i.y}} 500
150 153
{{ (, (adjSemiPrime y)+]) +/isMPerfect i.y}} 5000
1354 1365
{{ (, (adjSemiPrime y)+]) +/isMPerfect i.y}} 50000
12074 12110
{{ (, (adjSemiPrime y)+]) +/isMPerfect i.y}} 500000
108223 108326</syntaxhighlight>
 
=={{header|Phix}}==
6,962

edits