Jump to content

Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions

→‎{{header|C++}}: Added alternative, Pascal translation
m (→‎{{header|REXX}}: edlded a blank line, added an exit code.)
(→‎{{header|C++}}: Added alternative, Pascal translation)
Line 207:
1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624
</pre>
===Alternative===
{{Trans|Pascal}}
More terms and quicker than the straightforward C version above. [https://tio.run/##bVJNb9NAFLz7V0yLGu1ihzopJ38EIbgiJMSBG3J3N84KZ@1417QI5a8T3tuQNqm42W/emxnPWA3DvFXqcHhlneombVApH7TtV8nZZDP2jibJ5K1r4Zqt8UOjDGizKI5omSSqdz7AuoBP77@hxt2yTJBMztvWGR2B1oSP9qfVZvQfXBAXmJP4nQAXM800GXYZ9BfjM4zG02RBvHjY2M5AXAmHGRaSjuGwWjHKa2laYv@8JjReQ0tUddTBjmgcbqFL2DWI44a1auQMshbhOcsAuj@N0pqZSzqssSuJ47Zmgv1J5IzleIpomM74nBc1vyz5aTRhGh1RXZFjvIuLVUWPxVFjnyQcwLaxTrCni1hsBvcYMlCWFCNrDSPN1@L668ZgbUfq4UajccHOCaG6MHSTRzOaAtcZ9xMdNlPoqUT6HB9Mo399V12vfhSF6x@EpGQ4pMcQE48xxI/ivMRRmZAXjVoqoj5eseuTLTJDsvYplsiRpry2wluJ2QziBRNhkWop5b8jRENiwTkxjHnsfc7u9rCx8acqCKauTx965mPryYmgVyn0NDbB9q7S/XTfmZX4TwpE74N8o/qJPEn6iRZ5nksi3R8Of9S6a1p/mH@@@ws Try It Online!]<lang cpp>#include <cstdio>
#include <chrono>
 
using namespace std::chrono;
 
const int MAX = 32;
unsigned int getDividersCnt(unsigned int n) {
unsigned int d = 3, q, dRes, res = 1;
while (!(n & 1)) { n >>= 1; res++; }
while ((d * d) <= n) { q = n / d; if (n % d == 0) { dRes = 0;
do { dRes += res; n = q; q /= d; } while (n % d == 0);
res += dRes; } d += 2; } return n != 1 ? res << 1 : res; }
 
int main() { unsigned int i, nxt, DivCnt;
printf("The first %d anti-primes plus are: ", MAX);
auto st = steady_clock::now(); i = nxt = 1; do {
if ((DivCnt = getDividersCnt(i)) == nxt ) { printf("%d ", i);
if ((++nxt > 4) && (getDividersCnt(nxt) == 2))
i = (1 << (nxt - 1)) - 1; } i++; } while (nxt <= MAX);
printf("%d ms", (int)(duration<double>(steady_clock::now() - st).count() * 1000));
}</lang>
{{out}}
<pre>The first 32 anti-primes plus are: 1 2 4 6 16 18 64 66 100 112 1024 1035 4096 4288 4624 4632 65536 65572 262144 262192 263169 269312 4194304 4194306 4477456 4493312 4498641 4498752 268435456 268437200 1073741824 1073741830 223 ms</pre>
 
=={{header|Dyalect}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.