HDOJ_2.1.2_How many prime numbers
题目:
C++代码:
#include<iostream>
#include<cmath>
using namespace std;
int main(){//N为每组数据个数,num为质数的个数,data为遍历每个数据,i,j为循环变量int N,num,data,i,j;while(cin>>N){num=0;//遍历每个正整数for(i=0;i<N;i++){//标识是否为质数bool flag=true;cin>>data;for(j=2;j<=sqrt(data);j++){if(data%j==0){flag=false;break;}}if(flag){num+=1;}}cout<<num<<endl;}return 0;
}
运行结果:
HDOJ_2.1.2_How many prime numbers相关推荐
- Sum of Consecutive Prime Numbers POJ - 2739(线性欧拉筛+尺取法)
题意: 一些正整数可以由一个或多个连续质数的总和表示.给定一个的正整数n,问满足条件的有多少种情况? 题目: Some positive integers can be represented by ...
- CF385C Bear and Prime Numbers 数学
题意翻译 给你一串数列a.对于一个质数p,定义函数f(p)=a数列中能被p整除的数的个数.给出m组询问l,r,询问[l,r]区间内所有素数p的f(p)之和. 题目描述 Recently, the be ...
- 7-24 First 50 Prime Numbers (10 分)
7-24 First 50 Prime Numbers Your program reads one natural numbers n in, and prints out the sum of t ...
- poj 2739 Sum of Consecutive Prime Numbers
悲剧,如此水题,竟搞了许久.唉,只因题目没看清. 准确的说:应该是准备工作没做好就开始敲代码了!! 下次一定要想的很清楚了再code ing ! //144K 63MS #include <st ...
- CF385C Bear and Prime Numbers
思路: 需要对埃氏筛法的时间复杂度有正确的认识(O(nlog(log(n)))),我都以为肯定超时了,结果能过. 实现: 1 #include <bits/stdc++.h> 2 usin ...
- HOJ 1015 Nearly prime numbers
代码 //Nearly prime number is an integer positive number for which it is possible //to find such prim ...
- Sum of Consecutive Prime Numbers
我们都知道数字是个好玩意,那么我们想知道一个数字能是否能用若干个(或许是一个)连续的素数之和表示,并且想知道有多少种方法.例如,53 有两种表示方法 5 + 7 + 11 + 13 + 17 和 53 ...
- SGU 113 Nearly prime numbers
SGU_113 对数分解素因子即可,如果最后素因子的个数为1或者大于2自然无解. #include<stdio.h>#include<string.h>#include< ...
- hdu2.1.2 How many prime numbers(计算素数的个数)
给出一系列的数,统计素数的个数 思路:因为数据的范围为2^31-1,先计算出[2,sqrt(2^31-1]之间的素数primes.在判断给出的数num是否是素数时,只需要判断num是否能被primes ...
最新文章
- 学校通知,本学期不用返校了
- 深圳快测计算机技术有限公司,口罩快速检测出数据口罩快检预检办理
- 在python中定义类时、运算符重载_python自定义类运算符重载
- tomcat在linux下开机启动
- 软件安全测试:安全左移的痛点与要点
- easyui加载后台数据 笔记
- html图片鼠标动态效果代码,纯css3实现鼠标经过图片显示描述的动画效果
- 【django】 model_to_dict ‘QuerySet‘ object has no attribute ‘_meta‘
- 极限编程(xp),iso国际标准化组织
- 视频教程-带你轻松入门MATLAB-Matlab
- linux vi编辑器常用命令
- 修改redis配置文件,并以指定配置文件的方式启动
- 信安软考 第十四章 恶意代码防范技术原理
- e680 reboot的研究
- tgp助手登陆服务器未响应,LOL登陆服务器未响应解决方法
- Redis 增加互斥锁
- debian中双网卡上内外网的设置方法
- 无人机行业的机遇与挑战
- python实现位置定位_python定位位置
- 前端框架ice飞冰与java后台交互分享