您的位置:首页 > 其它

求素数

2016-05-19 22:35 302 查看

How many prime numbers

Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10683 Accepted Submission(s): 3504
 
[align=left]Problem Description[/align]Give you a lot of positive integers, just to find out how many prime numbers there are. 
[align=left]Input[/align]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. 
[align=left]Output[/align]            For each case, print the number of prime numbers you have found out. 
[align=left]Sample Input[/align]
32 3 4
 
[align=left]Sample Output[/align]
2
 
[align=left]Author[/align]wangye 
[align=left]Source[/align]HDU 2007-11 Programming Contest_WarmUp 
[align=left]Recommend[/align]威士忌 
#include <iostream>#include <stdio.h>#include <cmath>using namespace std;bool pao(int n){int i;int flag=0;if(n==2)return 1;for(i=2;i<sqrt(n)+1;i++){if(n%i==0){return 0;}}return 1;}int main(){int t;int x;while(cin>>t){int sum;sum=0;while(t--){cin>>x;if(pao(x)){sum++;}}cout<< sum<<endl;}return 0;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: