Use the filter method to find prime numbers within 100

Updated on technology 2024-05-16
9 answers
  1. Anonymous users2024-02-10

    Selection is a mathematical method.

    For example, find the prime number from 1 to 100.

    Then you can.

    first int a[101],i;

    for(i=1,i<101,i++)

    a[i]=i;

    Assign 1 to 100 to a[1] to a[100].

    You can make the multiples of 2 0

    0 is not judged.

    Make the multiple of 3 0

    The last output is a number that is not 0.

    In short, it is a batch of sifting.

  2. Anonymous users2024-02-09

    rojay*/

    #include

    #define

    length

    boolprime[length]

    voidprime_num(

    intijprime[0]

    prime[1]

    for(iilengthi

    if(prime[i]

    for(jiijlengthj

    iprime[j]

    intmain

    prime_num(

    After that, you can iterate over the array, or you can save the prime numbers directly in the above subfunction without iterating through them. The output will be done yourself.

    return

  3. Anonymous users2024-02-08

    Is it a programming problem?

    What program is written with.

  4. Anonymous users2024-02-07

    The sieve method to find the prime number is as follows:

    The basic idea of finding primes by sieve is to arrange a set of positive integers from 2 to n in order from smallest to largest. Remove multiples of 2, 3, and 5 until the root number n is multiple, and what remains is all the prime numbers between 2 n. If any:

    Remove the slag lift multiple of 2 (excluding 2), and the remaining number is:

    3 is the smallest of the remaining numbers, remove the multiple of 3, and so on until all the numbers have been sifted out, and the prime number is found as:

    The screening method is also known as the sieve method, and the specific method is: first arrange the n natural numbers in order. 1 is not a prime number, nor is it a composite number, it should be crossed out.

    The second number 2 is left over as a prime number, and all numbers after 2 that are divisible by 2 are crossed out. The first number that is not crossed out after Duan Sui 2 is 3, leave 3, and then cross out all the numbers that are divisible by 3 after 3.

    The first number that is not crossed out after 3 is 5, leave 5, such as Ranbi and then cross out all the numbers that are divisible by 5 after 5. If you continue to do this, you will filter out all the composite numbers that do not exceed n, leaving all the prime numbers that do not exceed n. Because the Greeks wrote numbers on waxed tablets, each time a number was crossed out, they wrote small dots on it, and when the search for prime numbers was complete.

    These many dots are like a sieve, so the Eratosthenian method is called the "Eratostheni sieve", or "sieve method" for short. (Another explanation is that the numbers were written on papyrus, and each time a number was crossed, the number was dug out, and when the search for prime numbers was done, the many small holes were like a sieve.) )

  5. Anonymous users2024-02-06

    Within 100 (6 times as the law) 2, type silver Qi, fight reputation,

  6. Anonymous users2024-02-05

    First, use the available enumeration method to obtain the natural number of 1-100. Then with a circular structure, each number is judged, and this number is divided to start from 2 and subtract 1 from itself (in fact, it can be judged to be one-half of this number). The output that is not divisible can be used.

  7. Anonymous users2024-02-04

    The basic idea of finding primes by sieving is to arrange the positive integers in a range starting from 1 in order from smallest to largest, 1 is not a prime number, and it is first sieved out. Select the smallest number for the rest of the numbers to be prime, and then remove its multiples.

    And so on until the sieve is empty.

    If any: 1 2 3 4 5 6 7 8 9 10

    1 is not a prime number, remove it. The smallest of the remaining numbers is 2, which is prime, and after removing the multiple of 2, the remaining number is:

    The smallest of the remaining numbers, 3, is the prime number, remove the multiple of 3, and so on until all the numbers have been sifted, and the prime number is found as:

  8. Anonymous users2024-02-03

    The law of the screening method: (take the prime number in 1 1000 as an example).

    We know the definition of a prime number: a prime number is divisible by 1 and itself, so if you look at it this way, as long as there is a number that is neither 1 nor the number itself and divides this number, it can mean that this number is not prime. For example, 5 is prime, because 5 is only divisible by 5 and 1, and 6 is not prime, because 6 is divisible by 2 and 3 in addition to being divisible by 1 and 6.

    Just imagine, we want to judge whether 6 is a prime number, do we need to cycle to 6 to judge it, no, because 2 and 3 are his factors, when we cycle to 2, we find all multiples of 2, such as 4, 6, 8, 10, 12, etc., these numbers have at least 2 this factor, so we can judge that they are not prime. And since 4 is a multiple of 2, it has been determined that 4 is not a prime number when the cycle reaches 2, so we don't need to dig out the multiple of 4, just skip 4, come to 5, dig out all the multiples of 5, and then 6, 6 is mined at the multiple of 2, so skip 6 and come to 7....The cycle is until the last number, which is what is said in the above 7 steps, and the remaining numbers that have not been mined (the meaning of digging out is to set this number to 0), that is, the number that is not 0 is the prime number.

    I don't know if you can understand what I'm saying. Hope it helps.

  9. Anonymous users2024-02-02

    Prime number memory method within 100.

    There are 25 prime numbers within 100, and we often use these prime numbers, which can be memorized in the following two ways.

    1. Regular memory method.

    First of all, remember 2 and 3, and the product of 2 and 3 prime numbers is the prime number within, which is generally in the position before and after the multiple of 6. Such as ......Only the numbers in the positions before and after these multiples of 6 are not prime numbers, and these numbers are multiples of 5 or 7. From this we can see:

    The two numbers in the front and back positions of multiples of 6 within 100 must be prime numbers as long as they are not multiples of 5 or 7. Based on this feature, prime numbers up to 100 can be memorized.

    2. Categorical mnemonics.

    We can divide prime numbers within 100 into five categories of memory.

    Category 1: Prime numbers within 20, a total of 8.

    The second category: the single digit is 3 or 9, and the ten digits are 3 prime numbers, a total of 6.

    The third category: the single digit is 1 or 7, and the ten-digit number is a prime number with a difference of 3, a total of 4.

    Category 4: The single digit is or 7, and the ten digits are 3 prime numbers, a total of 5.

    Category 5: There are 2 other holdings that are 79 and 97.

Related questions
17 answers2024-05-16

Don't mislead people upstairs, do you call it a screening method? >>>More

14 answers2024-05-16

If Company B, as the source of the first performance of the contract, fails to pay the processing fee as agreed in the contract, its behavior should be a breach of contract, but Company A did not propose to terminate the contract when Company B failed to pay the processing fee within the time limit agreed in the contract, so the processing contract is still legally binding on both parties, and Company B should still pay the processing fee in advance, and Company A is also obliged to deliver the goods. >>>More

4 answers2024-05-16

Gives a function that determines whether a number is prime or not. >>>More

2 answers2024-05-16

I have a lot of jokes here, and I'd love to share them with you. >>>More

15 answers2024-05-16

The application of the difference method in chemical calculation is based on the chemical change before and afterThe amount of matterThe changes that occur to find out the so-called "theoretical differences". The differences mainly include: >>>More