10: determine the number of prime numbers.

Source: Internet
Author: User

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 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.