-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrnCnt.java
58 lines (58 loc) · 1.62 KB
/
PrnCnt.java
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
56
57
58
import java.util.ArrayList;
import java.util.Iterator;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class PrnCnt
{
public static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static ArrayList<Integer> prime_list = new ArrayList<Integer>();
public static Iterator it;
public static boolean isPrime(int num)
{
int x=2;
if(num<=1)
return false;
else if(num<=3)
return true;
while(x<=(num/2))
{
if(num%x==0)
return false;
x++;
}
return true;
}
public static int MyPrimeRange(int ll,int ul) throws Exception
{
int count=0,sum=0;
for(int i=ll;i<=ul;i++)
{
if(isPrime(i))
prime_list.add(new Integer(i));
}
it = prime_list.iterator();
while(sum<ul)
{
if(it.hasNext())
sum+=(int)it.next();
if(sum == 2)
continue;
else if(isPrime(sum))
count++;
}
return count;
}
public static void main(String[] args) throws Exception
{
int ll,ul;
out.write("Enter The Lower And Upper Limit!!!\n->");
out.flush();
ll=Integer.parseInt(in.readLine());
ul=Integer.parseInt(in.readLine());
System.out.println(MyPrimeRange(ll,ul));
}
}