Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Anti-primes/Java/anti-primes.java
Normal file
25
Task/Anti-primes/Java/anti-primes.java
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
public class Antiprime {
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int maxDiv = 0, count = 0;
|
||||
System.out.println("The first 20 anti-primes are:");
|
||||
for (int n = 1; count < 20; ++n) {
|
||||
int d = countDivisors(n);
|
||||
if (d > maxDiv) {
|
||||
System.out.printf("%d ", n);
|
||||
maxDiv = d;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue