Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
prime_numbers.cpp File Reference

Get list of prime numbers. More...

#include <iostream>
#include <vector>
Include dependency graph for prime_numbers.cpp:

Functions

std::vector< int > primes (int max)
 
int main ()
 

Detailed Description

Get list of prime numbers.

See also
primes_up_to_billion.cpp sieve_of_eratosthenes.cpp

Function Documentation

◆ main()

int main ( void  )

main function

26 {
27 std::cout << "Calculate primes up to:\n>> ";
28 int n;
29 std::cin >> n;
31 for (int i = 0; i < ans.size(); i++) std::cout << ans[i] << ' ';
33}
T endl(T... args)
ll ans(ll n)
Definition: matrix_exponentiation.cpp:91
std::vector< int > primes(int max)
Definition: prime_numbers.cpp:12
Here is the call graph for this function:

◆ primes()

std::vector< int > primes ( int  max)

Generate an increasingly large number of primes and store in a list

12 {
13 max++;
15 std::vector<bool> numbers(max, false);
16 for (int i = 2; i < max; i++) {
17 if (!numbers[i]) {
18 for (int j = i; j < max; j += i) numbers[j] = true;
19 res.push_back(i);
20 }
21 }
22 return res;
23}
T max(T... args)
T push_back(T... args)
Here is the call graph for this function: