-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct_of_primes.cpp
More file actions
46 lines (40 loc) · 896 Bytes
/
Product_of_primes.cpp
File metadata and controls
46 lines (40 loc) · 896 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
//{ Driver Code Starts
// Initial Template for C++
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
// User function Template for C++
class Solution{
public:
bool primeNum(long long num)
{
for(int i = 2; i*i <= num; i++)
{
if(num % i == 0)
return false;
}
return true;
}
long long primeProduct(long long L, long long R){
long long int ans = 1;
for(long long i = L; i <= R; i++)
{
if(primeNum(i))
ans = (ans * i) % 1000000007;
}
return ans;
}
};
//{ Driver Code Starts.
int main(){
int t;
cin>>t;
while(t--){
long long L, R;
cin>>L>>R;
Solution ob;
cout<<ob.primeProduct(L, R)<<"\n";
}
return 0;
}
// } Driver Code Ends