Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <time.h>
- #include <vector>
- using namespace std;
- bool isPrime(int num)
- {
- if (num == 2) {
- return true;
- }
- if (num <= 1 || num % 2 == 0) {
- return false;
- }
- double sqrt_num = sqrt(double(num));
- for (int div = 3; div <= sqrt_num; div +=2)
- {
- if (num % div == 0) {
- return false;
- }
- }
- return true;
- }
- int main()
- {
- int N = 10'000'000;
- clock_t start, end;
- std::vector<int> list(N);
- list.clear();
- start = clock();
- for (int i = 0; i < N; i++) {
- bool prime = isPrime(i);
- if (prime) {
- list.push_back(i);
- }
- }
- end = clock();
- cout << endl << endl << (end - start) / ((double) CLOCKS_PER_SEC);
- cout << " sec \n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement