判断质数 How many prime numbers

【代码超详解】HDU 2138 How many prime numbers? 有多少个质数?(质数埃筛打表 + 判定,31 ms) 一、题目描述 How many prime numbers Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 27558 Accepted Submission(s): 9246(2019/11/11) Problem Descrip... 阅读详情


acm step


前面犯了很多小错误,思维不清晰吧

发现一篇文章,关于更多质数的问题,链接: http://blog.youkuaiyun.com/liukehua123/article/details/5482854  (素数判断算法(高效率))

#include<iostream>
#include<cmath>


using namespace std;


bool isprime(int a){
	int t=sqrt(a+0.0);// zhuyi
	for(int i=2;i<=t;++i){
		if(a%i==0)
			return false;
	}
	return true;//不要与else组合,犯这种小错误
}


int main(){
	int a,n,count;
	while(cin>>n){
		count=0;
		for(int i=0;i<n;++i){
			cin>>a;
			if(isprime(a))
				count++;
		}
		cout<<count<<endl;
	}
}


STM32 USART高级功能全解析:IrDA、DMA、硬件流控与低功耗唤醒 USART是嵌入式系统中最基础的串行通信外设,其核心原理在于同步/异步时序控制与数据帧收发机制。现代MCU如STM32通过深度集成IrDA调制解调、DMA直传通道、RS232/RS485硬件流控及Stop模式唤醒等扩展能力,显著提升通信可靠性、吞吐效率与能效比。其中,IrDA SIR采用RZI编码实现抗干扰红外传输,DMA通过TXE/RXNE事件驱动实现零CPU干预的连续数据流,而硬件流控(RTS/CTS/DE)和低功耗唤醒(WUF+UESM)则分别保障工业现场鲁棒性与电池级超长待机。本文围绕STM32平台 阅读详情

相关推荐

Linux运维踩坑实录:手把手教你修复LVM中PV显示[unknown]的诡异问题

本文详细解析了Linux运维中LVM物理卷(PV)显示[unknown]的故障现象及修复方法。通过分析问题根源、提供标准修复流程和特殊场景处理方案,帮助运维人员快速解决VG容量异常、PV状态丢失等问题,并分享预防措施与最佳实践,确保LVM存储系统的稳定运行。

weixin_26869081的博客 347

判断素数的2种方式

PTA 判断素数 Java 本题的目标很简单,就是判断一个给定的正整数是否素数。 输入格式: 输入在第一行给出一个正整数N(≤ 10),随后N行,每行给出一个小于231的需要判断的正整数。 输出格式: 对每个需要判断的正整数,如果它是素数,则在一行中输出Yes,否则输出No。 输入样例: 2 11 111 输出样例: Yes No import java.io.BufferedReader; im...

Samil_Hy的博客 669

Ghidra逆向分析实战:从安装JDK到解析STM32的bin文件(附SVD插件配置)

本文详细介绍了使用Ghidra进行STM32固件逆向分析的完整流程,从JDK安装配置到SVD插件的应用。通过实战案例展示如何解析bin文件、恢复符号信息以及利用SVD插件识别外设寄存器,帮助开发者高效完成嵌入式设备的逆向工程任务。

weixin_29309475的博客 643

用JAVA判断一个数是否为素数(质数)

素数(prime number)又称质数,有无限个。质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数的数称为质数。 有时经常遇到用java判断素数的问题,为大家贴上怎么用java判断出一个数是否为素数。 public static boolean isPrime(int N){ if( N for( int i = 2 ; i*i if( N % i =

灿夏 1万+

曙光服务器RAID配置避坑指南:MegaRAID SAS 9361-8i实战(含Foreign状态处理)

本文详细解析了曙光服务器搭配MegaRAID SAS 9361-8i控制器的RAID配置全流程,包括RAID0和RAID5的创建、Foreign状态处理及性能优化策略。特别针对磁盘迁移中的Foreign状态问题,提供了系统化的解决方案和高级恢复技巧,助力企业级IT运维提升存储配置的稳定性和可靠性。

weixin_29200741的博客 410

springcloud教程 -- 1.快速搭建入门级demo,看这一篇就够了

废话不多讲,跟紧我,开启你的SpringCloud初体验 首先回顾微服务的基本组成: [图片 here] 生产者:提供服务 消费者:消费服务 服务注册/发现中心:服务注册,发现,监控 所以,首先明白springcloud微服务的架构基础:生产者(client),消费者(client),服务注册/发现中心(server)

叶巨岩的博客 8万+

Eclipse总是运行上一个程序

Eclipse总是运行上一个程序解决方式: 运行eclipse不运行刚写的类,而是运行以前的类,原因是刚写的类没有main()或者有误。这和java的特点有关,程序的运行总是main()方法作为开始,现在的类不定义main(),就视作一个功能类。 解决:查看刚写的类main()有没有误,或者整个程序有没有误。 public class Demo01 { public static void main(String[] args) { } } ...

橙子姑娘 8115

实体对齐(Entity Alignment)相关论文与数据集整理

实体对齐(Entity Alignment)、知识图谱融合方法总结整理 年份 模型 主要思想 博文推荐 论文 代码 2019 Entity Alignment between Knowledge Graphs Using Attribute Embeddings 实体对齐数据集整理 名称 — DBpe-dia(DBP) LinkedGeoData(LGD) Geonames(GEO) YAGO ...

bjxxkjdxcdd的博客 1万+

(hdu step 2.1.2)How many prime numbers(判断一个数是否是质数)

题目:       How many prime numbersTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8513 Accepted Submission(s): 2716 Problem DescriptionGive you a lot

黄俊东的专栏 1993

5个IO口驱动188数码管:查理复用算法在TM52F1363上的极致应用

本文深入解析了如何利用查理复用算法,在TM52F1363单片机上仅用5个IO口驱动188数码管。通过精密的硬件连接与软件时序控制,结合高阻态和动态扫描策略,实现了在极致资源限制下的稳定显示,为成本敏感型嵌入式产品提供了高效的IO复用解决方案。

numpy6sculptor的博客 476

数字孪生教程大全之 我们如何构建数字孪生?数字孪生的五个级别都是什么

文章摘要 什么是数字孪生? 我们如何构建数字孪生? 开发智能数字孪生系统的框架 什么是数字孪生? 数字孪生是一个不言自明的术语,用于识别物理系统的数字化版本。数字孪生的最早参考来自大卫·格伦特(David Gelernter )的小说作品。在他 1995 年的书中,Gelernter 博士为读者提供了未来有趣的可能性——万维网。前网络书籍谈到了计算机系统上的镜像数字世界。有些人可能会争辩说,我们的 Meta-verse 是新的数字世界——现实世界的数字孪生。但是,还有其他可能性,时间可能会讲述一个更好的

iCloudEnd的博客 3629

HDU 2138 How many prime numbers

题目很简单,判断输入的素数(质数)的个数 米勒罗宾算法,还在学习中。。。。 ①一个总是犯的错误,总会WA。。。 Input:There are a lot of cases. Each case...... 然而每次自己都会忘记 while(scanf("%d",&amp;t)!=EOF) ②其实,这一题可以暴力。 但是你要知道暴力怎么优化对吧。 cin 变成scanf暂且不表...

117瓶果粒橙 128

(王道计算机组成原理)第二章数据的表示和运算-第三节:运算方法和运算电路 1(基本运算部件)

本文主要介绍了计算机组成原理中的加法器和算术逻辑单元(ALU)的基本概念与实现原理。首先,文章详细讲解了一位全加器的工作原理,包括其输入输出、逻辑表达式及真值表。接着,介绍了并行加法器的两种类型:串行进位和并行进位的加法器,分析了它们的优缺点。随后,文章探讨了带标志位的加法器,说明了如何通过标志位生成逻辑来判断加法结果的状态。最后,文章阐述了ALU的功能及其实现原理,包括ALU的基本结构、控制信号的作用以及在实际考试中的图示表示。通过这些内容,读者可以全面了解加法器和ALU在计算机中的重要作用及其工作原理。

快乐江湖的博客 3837

hdu2138(How many prime numbers:查找多少个质数)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2138 题目描述: 思路: 就判断数字是否为质数就直接看其能否整除除自身与1的数,如果可以就将标志位设置为1. 还有一个注意点就是,题目说的是有多组数据,所以接受n值时要设置个!=EOF,因为是英文写的最开始没注意(终究还是吃了没文化的亏,哎) ac代码 #include<stdio.h&gt...

zhoupingqi2017的博客 225

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDUOJ 2138 How many prime numbers

#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define CLOSE() ios::sync_with_stdio(fal

%%% 469

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

HDU2138 How many prime numbers

本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作。 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/转载请注明出处,侵权必究,保留最终解释权! 题目链接:HDU2138 正解:$Miller-Rabin$素数测试+二次探测 解题报告:   $Millr-...

dgoh41514的博客 218

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

【HDU2138】—How many prime numbers(Miller-Rabin)

传送门 二次探测: 对于质数ppp,满足x2≡1(%p)x^2\equiv 1(\%p)x2≡1(%p)的只有x≡1(%p)x\equiv 1(\%p)x≡1(%p)和x≡p−1(%p)x\equiv p-1(\%p)x≡p−1(%p) 直接搬仲爺的博客了 #include<bits/stdc++.h> using namespace std; const int RLEN=1&l...

Stargazer的博客 227

How many prime numbers

How many prime numbers Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 35   Accepted Submission(s) : 11 Font: Times New Roman | Verdana

u011455899的专栏 720

HDU 2138 How many prime numbers 质数个数

/* 2138 ( How many prime numbers ) 判断质数的个数 */ #include #include //using namespace std; int main(){ int i,j,f,k,n,m,b; while(scanf("%d",&n)!=EOF) { k=0;

小人物的草稿本 715

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; //遍历每个正...

z2bns的博客 172

hdu how many prime numbers 筛选法求素数

/* * hdu How many prime numbers * date 2014/5/13 * state AC */ #include #include #include using namespace std; bool isPrime(int x) { int sqr=sqrt(x*1.0); for(int i=2;i<=sqr;i++) {

Just Do IT 950

hdoj--2138--How many prime numbers(暴力模拟)

How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14686    Accepted Submission(s): 5093 Problem Description   Gi

playboy307 452

【杭电oj】2138 - How many prime numbers(判断素数新方法)

How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14851    Accepted Submission(s): 5143 Problem Description

wyg1997 936

How many prime numbers(素数)

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 representin...

weixin_33989780的博客 189
上一篇: 最小公倍数,最大公约数
下一篇: 数据结构及简单算法的总结----之【排序】
eclipse_c
博客等级 码龄14年 28粉丝 162原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值