10: determine the number of prime numbers.
10: determine the number of prime numbers
- View
- Submit
- Statistics
- Question
-
Total time limit:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
Enter two integers X and Y to output the number of prime numbers (including X and Y) between them ).
-
Input
-
Two integers X and Y (1 <= X, Y <= 105 ).
-
Output
-
Returns an integer that represents the number of prime numbers (including X and Y) between X and Y ).
-
Sample Input
-
1 100
-
Sample output
-
25
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 using namespace std; 6 char a[10001]; 7 int b[10001]; 8 int maxn=-1; 9 char ans=0;10 int beginn;11 int endn;12 int now;13 int tot;14 int flag=0;15 int main()16 {17 int x,y;18 cin>>x>>y;19 for(int i=min(x,y);i<=max(x,y);i++)20 {21 flag=0;22 for(int j=2;j<=sqrt(i);j++)23 {24 if(i%j==0)25 {26 flag=1;27 break;28 }29 30 }31 if(flag==0)32 tot++;33 }34 if(min(x,y)==1)35 cout<<tot-1;36 else cout<<tot;37 return 0;38 }