Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
62
Task/Cuban-primes/D/cuban-primes.d
Normal file
62
Task/Cuban-primes/D/cuban-primes.d
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import std.math;
|
||||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
long[] primes = [3, 5];
|
||||
|
||||
immutable cutOff = 200;
|
||||
immutable bigUn = 100_000;
|
||||
immutable chunks = 50;
|
||||
immutable little = bigUn / chunks;
|
||||
immutable tn = " cuban prime";
|
||||
writefln("The first %s%ss:", cutOff, tn);
|
||||
int c;
|
||||
bool showEach = true;
|
||||
long u;
|
||||
long v = 1;
|
||||
for (long i = 1; i > 0; ++i) {
|
||||
bool found;
|
||||
u += 6;
|
||||
v += u;
|
||||
int mx = cast(int)ceil(sqrt(cast(real)v));
|
||||
foreach (item; primes) {
|
||||
if (item > mx) break;
|
||||
if (v % item == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
c++;
|
||||
if (showEach) {
|
||||
for (auto z = primes[$-1] + 2; z <= v - 2; z += 2) {
|
||||
bool fnd;
|
||||
foreach (item; primes) {
|
||||
if (item > mx) break;
|
||||
if (z % item == 0) {
|
||||
fnd = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!fnd) {
|
||||
primes ~= z;
|
||||
}
|
||||
}
|
||||
primes ~= v;
|
||||
writef("%11d", v);
|
||||
if (c % 10 == 0) writeln;
|
||||
if (c == cutOff) {
|
||||
showEach = false;
|
||||
writef("\nProgress to the %sth%s: ", bigUn, tn);
|
||||
}
|
||||
}
|
||||
if (c % little == 0) {
|
||||
write('.');
|
||||
if (c == bigUn) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
writefln("\nThe %sth%s is %17s", c, tn, v);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue