HDU 2138 How many prime numbers

来源:互联网 发布:淘宝用户数据分析 编辑:程序博客网 时间:2024/04/28 15:56

链接:http://acm.hdu.edu.cn/showproblem.php?pid=2138

 

哎,学了太多,忘了根本,直接素数判断累加就好了

之前居然考虑要打表神马的。。

因为题目没给数的大小。。又是各种超时,RE。。。闷

 

 

#include<iostream>#include<stdio.h>#include<cmath>using namespace std;int prime(int n){    if(n==2||n==3)return 1;int i;for(i=2;i<=sqrt((double)n);i++){if(n%i==0)return 0;}return 1;}int main(){int n;while(scanf("%d",&n)!=EOF){int i;int sum=0;int temp;for(i=0;i<n;i++){scanf("%d",&temp);if(prime(temp)==1)sum++;}printf("%d\n",sum);}return 0;}