Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Anti-primes/D/anti-primes.d
Normal file
28
Task/Anti-primes/D/anti-primes.d
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import std.stdio;
|
||||
|
||||
int countDivisors(int n) {
|
||||
if (n < 2) {
|
||||
return 1;
|
||||
}
|
||||
int count = 2; // 1 and n
|
||||
for (int i = 2; i <= n/2; ++i) {
|
||||
if (n % i == 0) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void main() {
|
||||
int maxDiv, count;
|
||||
writeln("The first 20 anti-primes are:");
|
||||
for (int n = 1; count < 20; ++n) {
|
||||
int d = countDivisors(n);
|
||||
if (d > maxDiv) {
|
||||
write(n, ' ');
|
||||
maxDiv = d;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
writeln;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue