Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class TestClass {
- static int[] sieveOfEratosthenes(int n) {
- int[] sieve = new int[n + 5];
- Arrays.fill(sieve, 1);
- sieve[0] = 0;
- for (int i = 2; i * i < sieve.length; i++)
- for (int j = i * i; j < sieve.length; j += i)
- sieve[j] = i;
- return sieve;
- }
- public static void main(String args[] ) throws Exception {
- int[] sieve = sieveOfEratosthenes(1000000);
- Scanner sc = new Scanner(System.in);
- int testCases = sc.nextInt();
- for (int testCase = 1; testCase <= testCases; testCase++) {
- int n = sc.nextInt();
- System.out.println(n / sieve[n] - sieve[n]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement