for example
void fun (int n) {
int a = 0;
double c, b = Math.sqrt(n);
boolean b;
for (int i=2; i<n; i+) {
b = true;
for (int j=2; j<=(int)Math.sqrt(i); j++) {
if (i%j == 0) {
b = false;
break;
}
}
if (b) {
a++;
}
}
c = a/b;
System.out.printf("A=%d, B=%.2f, C=%.2f", a, b, c);
}
public class Sieve {
public static void main(String[] s) {
int n = 2000000;
int count = sieveCount(n);
double j = Math.sqrt(n);
double result = count/j;
System.out.println(count);
System.out.println(j);
System.out.println(result);
}
public static int sieveCount(int n) {
BitSet b = new BitSet(n + 1);
int count = 0;
int i;
for (i = 2; i <= n; i++)
b.set(i);
i = 2;
while (i * i <= n) {
if (b.get(i)) {
count++;
int k = 2 * i;
while (k <= n) {
b.clear(k);
k += i;
}
}
i++;
}
while (i <= n) {
if (b.get(i))
count++;
i++;
}
return count;
}
}