forked from Twiggecode/Integer-Sequences
-
Notifications
You must be signed in to change notification settings - Fork 0
/
primorial.cpp
55 lines (41 loc) · 920 Bytes
/
primorial.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
C++ Program to find the product of the first n primes as nth primorial number.
*/
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000005
bool marked[MAX];
vector<int> primes;
void sieve()
{
marked[0] = marked[1] = true;
for(int i = 2; i * i <= MAX - 1; i++){
if(marked[i] == false){
for(int j = i*i; j <= MAX - 1; j += i){
marked[j]=true;
}
}
}
for (int i = 0; i < MAX; i++){
if(!marked[i]){
primes.push_back(i);
}
}
}
long long int findPrimorial(int n) {
long long int result = 1;
for (int i = 0; i < n; i++) {
result *= primes[i];
}
return result;
}
// Main Function
int main()
{
int n;
sieve();
cout<< "Enter a number: ";
cin>> n;
cout<< "The " << n << "th number's primorial value is: " << findPrimorial(n) << "\n";
return 0;
}