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

  Implement simple java program to input syllabus grades

To implement simple Java program to input (hypothetical) syllabus grades, computing and displaying both normal Mean and Harmonic Mean.

  Create a recursive factorial program

Assignment 1: 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 !. For example, if the input is 4, the output could be:

  Alter the prototype form page by javascript function

Alter the prototype form page so that when JavaScript function has verified that all the required fields have been filled, cookie is added to user's computer.

  Create a project in eclipse

Create a new project

  Write specifications for method which advances date by one

Write specifications for the method which advances any given date by one day. Comprise a statement of purpose, pre- and post-conditions, and description of parameters.

  Write various bindings to determine semantics

Write the various bindings that are required to determine the semantics when statement is executed. For each binding, indicate binding time used for language. Describe your answer.

  Write the logical expression in postfix notation.

Given symbols p, q, r, and s for propositions. Draw the binary tree representation of the logical expression ((p || r) && ! p ) || s) && (q || r). Write the logical expression in postfix notation.

  A jsp expression can contain any java expression

A JSP expression can contain any Java expression that evaluates to a

  Eclipse or netbeans environments

As recommendation, you can try to use Eclipse or NetBeans environments that are used also for other courses as: Introduction in Java programming and Intermediate programming.

  Implement the application using a singly linked list

Implement the following application using a singly linked list. This application accepts from console and stores a list of 10 names of your friends in the singly linked list

  Write servlet code for accepting two numbers from user

Write the servlet code for accepting two numbers from user show addition and multiplication of numbers. If error occurs, then call JSP error page to display suitable error message.

  Develop class which implements interface

Let the ADT called SquareMatrix. (The matrix can be represented by 2-D array of ints w/ n rows and n columns.) Write specification for ADT as Java interface. Develop the class which implements interface.

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