Method to calculate all primes in the range [2..n]

Assignment Help JAVA Programming
Reference no: EM13161155

One commonly used method to calculate all primes in the range [2..n] is to start with the number 2, mark it as prime, and mark all its multiples (excluding itself) as not prime. Then, we find the next smallest unmarked number, mark it as prime, and mark all its multiples (excluding itself) as not prime. Continuing this way, we get a list of all primes.


Now, let us say that we modified the above algorithm, and start with n instead of 2. We mark it as prime, and mark all its factors (excluding itself) as not prime. Then we find the next greatest unmarked number, mark it as prime, and mark all its factors (excluding itself) as not prime. Continuing this way, we get a list of all primes.

Now you wonder, given a value of n, how many numbers are such that both the above algorithms will mark them as prime?


Input


The first line contains T the number of test cases. Each of the next T lines contain an integer n.


Output

Output T lines, one for each test case, containing the required answer.

Example

Sample Input :
3
2
4
7

Sample Output :
1
1
2

Constraints

1 <= T <= 100000
2 <= n <= 10000000

 

 

Reference no: EM13161155

Questions Cloud

Write c++ program that reads in the average monthly rainfall : Write a C++ program that reads in the average monthly rainfall for a city for each month of the year and then reads in the actual monthly rainfall for each of the previous 12 months
State and draw the six conformers in newman projection : Draw the six conformers in newman projection for the 60 degree intervals from 0 to 360 degrees for carbon atoms 3 and 4. Clearly show which carbon is represented by the "dot" and the "circle" Show which C
Hidden implementations are often said : Hidden implementations are often said to exist in a black box. Do you agree with this statement? Why or why not? Identify the advantages and disadvantages of using this approach in both programming and real life?
Compute the work done : A coffee cup calorimeter is being used in this lab despite the fact that one of the reactions produces gas. Calculate the work done using the information
Method to calculate all primes in the range [2..n] : One commonly used method to calculate all primes in the range [2..n] is to start with the number 2, mark it as prime, and mark all its multiples (excluding itself) as not prime. Then, we find the next smallest unmarked number, mark it as prime, and m..
To simplify the problem, the values can each be placed : Use Notepad to place the following value in a text file: 86, 97, 144, 26. To simplify the problem, the values can each be placed on separate lines
Explain obtain the positions of the wavefunctions nodes : obtain the positions of the wavefunctions nodes from the roots of the corresponding Hermite polynomial, and (d) from your answers to (b) and (c), sketch the wave functions, indicating nodes and boundary conditions behaviors at +/- infinite in the ..
Generated by some condition that occurs as a result : Program: Generated by some condition that occurs as a result of an instruction execution, such as arithmetic overflow, division by zero, attempt to execute an illegal machine instruction, and reference outside a user's allowed memory space.
The arrangement of a group of variables along a grid : a two-dimensional array is nothing more than the arrangement of a group of variables along a grid. Each variable occupies a specific row and column

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd