ubuntu16.04+vscode+opencv3.1- Read the picture Jen

2023-01-25   ES  

To get all the prime number of natural number N, it must be not greater than

The multiples of all prime numbers of are removed, and the rest are prime numbers.

Give it to sievevaluerange n, find out
1 is neither quality nor number, remove;
Use 2 to sieve first, that is, leave 2, remove the multiple of the 2;
Use the nextquality, that is, 3 sieves, leave 3, remove the multiple of 3;
Next, use the next quality 5 sieve, leave 5, and 5multipleRemove; Repeat it constantly …
Mainly use BITSET type

 1 #include<iostream>
 2 #include<string>
 3 #include<bitset>
 4 #include<cmath>
 5 
 6 using namespace std;
 7 int main()
 8 {
 9     int const max_number(32);
10     int const max_test((int)sqrt((double)max_number));
11     bitset<max_number + 1> number;
12     number.set();
13     number[1] = 0;
14     for (int i(1); i!=max_test; ++i)
15     {
16         if (number[i]){
17             //S screening multiple
18             for (int j(i*i); j <max_number + 1; j += i)
19             {
20                 number[j] = 0;
21             }
22         }
23     }
24     cout << "The number of the primes less than " << max_number + 1
25         << "is" << number.count() << endl;
26     for (int i(1); i != max_number + 1; ++i)
27     {
28         if (number[i]) cout << i << ",";
29     }
30     cout << endl;
31     system("pause");
32 }

Reprinted: https://www.cnblogs.com/dameidi/p/9313461.html

source

Related Posts

Android realizes sliding suspension top effect Shirly

[LINUX Learning Notes] LINUX process descriptor TaskStruct detailed explanation

Python Frequently Asked Questions Summary

ubuntu16.04+vscode+opencv3.1- Read the picture Jen

ubuntu16.04+vscode+opencv3.1- Read the picture Jen

Random Posts

The most dirty technical interpretation in history, I even understood in seconds

(2) Install and configure Eclipse and JDKGZJASON under MAC

MyBatis Plus uses QueryWrapper to query in queries

ARM interrupt vector table of simple analysis

【吴恩达】机器学习ex3编程练习