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

{
std::cout << "Calculate primes up to:\n>> ";
int n;
std::cin >> n;
std::vector<int> ans = primes(n);
for (int i = 0; i < ans.size(); i++) std::cout << ans[i] << ' ';
std::cout << std::endl;
}
std::cin
std::cout
std::endl
T endl(T... args)
ans
ll ans(ll n)
Definition: matrix_exponentiation.cpp:91
primes
std::vector< int > primes(int max)
Definition: prime_numbers.cpp:12
std::vector< int >
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

{
max++;
std::vector<int> res;
std::vector<bool> numbers(max, false);
for (int i = 2; i < max; i++) {
if (!numbers[i]) {
for (int j = i; j < max; j += i) numbers[j] = true;
res.push_back(i);
}
}
return res;
}
std::max
T max(T... args)
std::vector::push_back
T push_back(T... args)
Here is the call graph for this function: