Practice Question 5
Question 5. Write a Program to find the product of n prime numbers.
Product
class Solution{ static long primeProduct(long L, long R){ long s = 1; int MOD = 1000000007; for(long i = L ; i <= R ;i++) { if(fact(i)) { s = (s * i )%MOD ; } } return s; } public static boolean fact(long k) { if(k == 1 || k == 0) return false; else if(k == 2) { return true; } else if(k%2 == 0) return false; else { for(int i = 3 ; i <= Math.sqrt(k) ; i++) { if(k%i == 0) return false; } return true; } } } |