Menu

[r350]: / XKPRIME.MPL  Maximize  Restore  History

Download this file

23 lines (18 with data), 377 Bytes

/*
  ALMOST PRIME - MPL VERSION
  CONVERTED FROM C
  HTTPS://ROSETTACODE.ORG/WIKI/ALMOST_PRIME#C
*/

##LIBHDR

KPRIME(N,K;P,F) [
  F=0; P=2; F<K && *P<=N @ [ ==(N\P) @ [N/=P;++F]; ++P ];
  F+(N>1)==K
]

.(;I,C,K) [
  K=1; K<=5 @ [
    WRITEF("K = %N:",K);
    I=2; C=0; C<10 @ [ KPRIME(I,K) ? [ WRITEF(" %N",I); ++C]; ++I ];
    NEWLINE();
    ++K
  ]
]
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.