-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimorial_Number.cpp
More file actions
52 lines (46 loc) · 831 Bytes
/
Primorial_Number.cpp
File metadata and controls
52 lines (46 loc) · 831 Bytes
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
/*
Premorial Number is the product of first N prime number just like factorial
P#5 = (Primorial of 5) = 2*3*5*7*11 = 2310
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define module 10000000007
bool isPrime(int x){
if(x == 1 || x == 0)
return false;
for(int i = 2; i<=sqrt(x); i++){
if(x%i==0){
return false;
}
}
return true;
}
void primorial(int n){
ll result = 1;
int count = 0;
int j = 2;
while(1){
if(isPrime(j)){
result = result*j;
count++;
}
if(count == n){
break;
}
j++;
}
result = result%module;
cout<<result<<endl;
}
int main() {
//code
int t;
cin>>t;
while(t-->0){
int n;
cin>>n;
primorial(n);
}
return 0;
}