Loading...
Searching...
No Matches
primes_up_to_billion.cpp File Reference
Compute prime numbers upto 1 billion. More...
#include <cstring>
#include <iostream>
Include dependency graph for primes_up_to_billion.cpp:
Go to the source code of this file.
Variables char prime [100000000] Detailed DescriptionCompute prime numbers upto 1 billion.
Definition in file primes_up_to_billion.cpp.
Function Documentation ◆ main()Main function
Definition at line 26 of file primes_up_to_billion.cpp.
26 {
28 int64_t n;
29 std::cin >> n; // 10006187
30 if(
prime[n] ==
'1')
31 std::cout << "YES\n";
32 else
33 std::cout << "NO\n";
34
35 return 0;
36}
◆ Sieve()Perform Sieve algorithm
Definition at line 13 of file primes_up_to_billion.cpp.
13 {
14memset(
prime,
'1',
sizeof(
prime));
// intitize '1' to every index 15 prime[0] =
'0';
// 0 is not prime 16 prime[1] =
'0';
// 1 is not prime17 for (int64_t p = 2; p * p <= n; p++) {
18 if(
prime[p] ==
'1') {
19 for (int64_t i = p * p; i <= n; i += p)
20 prime[i] =
'0';
// set all multiples of p to false21 }
22 }
23}
Variable Documentation ◆ primeRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4