HDOJ 2138-How many prime numbers

╰半夏微凉° 2022-08-19 11:08 21阅读 0赞

How many prime numbers

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 14844 Accepted Submission(s): 5140

Problem Description

Give you a lot of positive integers, just to find out how many prime numbers there are.

Input

There are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won’t exceed 32-bit signed integer, and each of them won’t be less than 2.

Output

For each case, print the number of prime numbers you have found out.

Sample Input

  1. 3
  2. 2 3 4

Sample Output

  1. 2

Author

wangye

Source

HDU 2007-11 Programming Contest_WarmUp

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<cmath>
  4. #include<algorithm>
  5. using namespace std;
  6. bool F(int cmp)
  7. {
  8. for(int i=2;i<=sqrt(cmp);i++)
  9. {
  10. if(cmp%i==0)
  11. return false;
  12. }
  13. return true;
  14. }
  15. int main()
  16. {
  17. int nn;
  18. while(scanf("%d",&nn)!=EOF)
  19. {
  20. int i,j=0;
  21. for(i=0;i<nn;i++)
  22. {
  23. int yy;
  24. scanf("%d",&yy);
  25. if(F(yy))
  26. j++;
  27. }
  28. printf("%d\n",j);
  29. }
  30. return 0;
  31. }

发表评论

表情:
评论列表 (有 0 条评论,21人围观)

还没有评论,来说两句吧...

相关阅读

    相关 How Many Tables

    Problem Description: 今天是伊格内修斯的生日。他邀请了很多朋友。现在是晚餐时间。伊格内修斯想知道他至少需要多少张桌子。你必须注意,并非所有的朋友都彼此认识