如何快速判断一个数是否为2的倍数?(正整数)

算法总结:判断一个数是否为素数 1.约定 x%y为x取模y,即x除以y所得的余数,当x象都为整数。 x^y表示x的y次方。乘方运算的优先级高于乘除和取模,加减的优先级最低。 见到x^y/z这样,就先算乘方,再算除法。 A/B,称为A除以B,也称为B除A。 若A%B=0,即称为A可以被B整除,也称B可以整除A。 A*B表示A乘以B或称A乘B,B乘A,B乘以A……都一样。 复习一下小学数学 公因数:两个不同的自然 阅读详情

如何快速判断一个数是否为2的倍数?(正整数)

解法一:暴力解法

 一个数是否为2的倍数,可分为两者情况1和非1。

 1显然是2的倍数,至于其他情况我们仅需暴力模2、处2循环,一旦出现模2结果非0的情况,则表明该数不是2的倍数!

bool func(int x) // x >= 0
{
   
   
	if (x == 0) return true;
	else
	{
   
   
		while (x)
		{
   
   
			if (x % 2) return false;
			x /= 2;
		}
		return true;
	}
}

解法二:lowbit(x&-x)

 首先,如果一个数是2的倍数,此时该数都对应的二进制只存在唯一 一个1(比如8对应1000

如何进行快速求解大数是否是11的倍数证明(如果奇数位数字和与偶数位数字和的差是11的倍数,则这个数是11的倍数) 数学小结论证明 阅读详情

相关推荐

OFDM基本原理

OFDM基础介绍,包括OFDM的核心思想,数学推导了OFDM信号的调制解调过程。

伊丽莎白的学习之路 8904

OpenNARS开源通用人工智能系统:非公理推理引擎实践指南

人工智能系统从基于规则推理到深度学习模型,始终围绕如何让机器具备智能决策能力。传统逻辑系统依赖公理和完备知识,而现实世界智能体需要在资源受限、信息不完备环境下进行推理。非公理推理系统(NARS)通过动态真值计算和信念修正机制,实现了在不确定性环境下的自主学习和决策。这种推理引擎的技术价值在于模拟人类思维的核心机制——归纳、演绎和学习,为通用人工智能(AGI)提供了不同于数据驱动的新路径。在应用场景上,NARS适用于游戏NPC决策、复杂系统故障诊断和自适应机器人控制等领域。OpenNARS作为NARS理论的开

weixin_31961675的博客 406

百度地图街景图像批量获取

由于个人研究需要在最近试了一下使用API获取百度地图街景图片,在此介绍一下基于我个人需求的百度街景批量获取方法,本文以Python编码作为主要方法,如果对零编码工具有需要的可以关注一下UA城市分析小组刚刚发布的街景图片获取工具。 街景图像用作区域细粒度空间指标测度需要解决几个问题。 1. 首先就是调用额度的限制,现在百度对于个人认证开发者每天可用的街景图像调用额度为100张,在不考虑购买额度上限(1万张600元,其实有经费的前提下可以直接考虑钞能力)的情况下动辄几千上万张的爬取数量会大大增加需要爬取的时间周

boycetoon29的博客 1万+

Obsidian笔记同步实战:基于Git的私有化部署与自动化管理

本文详细介绍了如何利用Git为Obsidian笔记构建私有化、自动化且免费的同步方案。通过安装配置Git与Obsidian-git插件,结合Gitee等远程仓库,实现笔记的版本管理、多设备同步与自动备份,打造安全可靠的知识管理体系。

y7z8a的博客 272

数据分析(二):学生成绩预测分析报告

表1 特征变量描述变量描述school学生的学校sex学生的性别age学生的年龄address学生的家庭住址类型famsize家庭规模Pstatus父母同居状况Medu母亲的教育Fedu父亲的教育Mjob母亲的工作Fjob父亲的工作reason选择学校的理由guardian学生监护人traveltime从家到学校的时间studytime每周学习时间failures过去的类失败次数schoolsup额外的教育支持famsup家庭教育支持。

m0_73963149的博客 4414

运动控制软件:Siemens Sinamics二次开发_(6).通信接口与协议详解

PROFIBUSPROFINETModbus TCPCANopenEtherCAT每种通信接口都有其特定的应用场景和优势。选择合适的通信接口可以显著提高系统的性能和可靠性。在选择通信协议时,需要根据具体的应用场景和需求综合考虑。每种通信协议都有其特定的优势和局限性,因此在设计运动控制系统时,应选择最适合的协议,以确保系统的性能、可靠性、成本和维护性。通过以上对比和分析,希望开发者能够更好地理解和选择适合的通信接口和协议,从而优化运动控制系统的开发和应用。

2401_87715305的博客 898

RK3568下GPIO模拟串口

在嵌入式开发中,硬件 UART 资源可能被其他外设占用。此时,通过 GPIO 模拟 UART(软串口)成为一种灵活的解决方案。本文基于 RK3568 平台,结合 Linux 内核模块,实现高精度软串口通信,并深入分析关键技术细节。可以看到已经接收到数据了,可以自己创建自定义的设备文件到/dev下,也可以按照串口设备的标准创建一个设备,后面有时间我写一篇和标准串口设备结合的gpio模拟串口文章。RK3568 GPIO 模拟串口(软串口)实现详解。将编译好的驱动放到板子上运行。再写个Makefile。

文石_2009的博客 363

【GB28181】wvp-GB28181-pro部署安装教程(Ubuntu平台)

初始环境安装。

废人一枚的博客 5079

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

深度学习工具包 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")

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

上一篇: C++11重大新增特性:左值引用 & 右值引用 & 移动构造 & 移动赋值
下一篇: C++11新增特性:lambda表达式、function包装器、bind绑定
小白debug~
小白debug~ 新星创作者: C/C++技术领域 新星创作者: C/C++技术领域
博客等级 码龄4年 3510粉丝 128原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小白debug~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值