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 }
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++;
14  std::vector<int> res;
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 }
Here is the call graph for this function:
primes
std::vector< int > primes(int max)
Definition: prime_numbers.cpp:12
std::vector< int >
ans
ll ans(ll n)
Definition: matrix_exponentiation.cpp:91
std::vector::push_back
T push_back(T... args)
std::cout
std::endl
T endl(T... args)
std::max
T max(T... args)
std::cin