UVa 10892 LCM Cardinality (数论&素因子分解)

Python爬虫实战:利用Playwright与异步技术高效抓取链家十万级二手房数据 在开始编写代码之前,我们首先需要为项目选择合适的技术栈。1. 传统方案:Requests + BeautifulSoup优点: 简单、轻量、学习成本低。直接发送HTTP请求获取HTML,然后解析。缺点: 对于大量由JavaScript动态渲染的内容无能为力。现代网站(包括链家)大量使用JS来加载数据和实现交互,简单的HTTP请求无法获取到完整的页面内容。此外,容易被基于IP或请求头特征的反爬机制拦截。2. 进阶方案:Selenium优点。 阅读详情

10892 - LCM Cardinality

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=1833

A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the number of different integer pairs with LCM is equal to N can be called the LCMcardinality of that number N. In this problem your job is to find out the LCM cardinality of a number.

Input

The input file contains at most 101 lines of inputs. Each line contains an integer N (0<N<=2*109). Input is terminated by a line containing a single zero. This line should not be processed.

Output

For each line of input except the last one produce one line of output. This line contains two integers N and C. Here N is the input number and Cis its cardinality. These two numbers are separated by a single space.

Sample Input      Output for Sample Input

2
12
24
101101291        
0                

2 2

12 8

24 11

101101291 5


思路:

1. 设n=lcm(a,b)=(p1^r1)*(p2^r2)*(p3^r3)…(pm^rm)

又设a=(p1^a1)*(p2^a2)*(p3^a3)…(pm^am),b=(p1^b1)*(p2^b2)*(p3^b3)…(pm^bm)

则由lcm的定义有ri=max{ai,bi}

所以对于每个ri,ai和bi中至少有一个要取ri

2. 对于ai取ri的情况,bi可以取[0,ri-1]的任意整数,这有ri种情况;bi取ri的情况同样是ri种。最后加上ai和bi都取ri的情况,共有(2*ri+1)种情况

3. 最后,由于这么考虑把(a,b)和(b,a)算重复了,但(n,n)的情况只算了一遍,所以最后要ans=(ans+1)/2=ans/2+1(因为ans是奇数)

4. 优化:只考虑√n范围内的质数,但这样会存在漏掉一个大质数的情况(比如n=2*101等),这个大质数的幂次只能为1(即少算了一个*(2*1+1)),所以在这种情况发生时要补上ans*=3,写成位运算就是ans+=ans<<1了。


另附:两道此题的扩展题。

NOIP2001普及组

HDU 4497


完整代码:

/*0.012s*/

#include <cstdio>

int main(void)
{
	long long n, nn, ans, i, count;
	while (scanf("%lld", &n), n)
	{
		nn = n;
		ans = 1;
		for (i = 2; i * i <= n; i += 2)///不用求素数,因为范围很小(注意n在不断减小)
		{
			if (n % i == 0)
			{
				count = 0;
				while (n % i == 0)
				{
					n /= i;
					++count;
				}
				ans *= (count << 1) + 1;
			}
			if (i == 2)
				--i;///小技巧
		}
		if (n > 1)
			ans += ans << 1;
		ans = (ans >> 1) + 1;
		printf("%lld %lld\n", nn, ans);
	}
	return 0;
}

【人工智能】在 cc-switch 中配置 AnyRouter 接入 Claude Code 完整指南 本文介绍了在cc-switch工具中配置AnyRouter中转服务以接入Claude Code的详细步骤。主要内容包括:1) 准备API令牌和端点地址;2) 填写基础信息和模型参数;3) 保存配置并重启终端生效;4) 常见问题排查方法。重点强调了API地址格式、模型ID准确性以及配置写入的必要性,帮助用户顺利完成中转服务配置,实现Claude 4.5版本的正常使用。 阅读详情

相关推荐

K8S证书过期解决办法之替换证书

k8s证书过期解决方案之替换证书

q_hsolucky的博客 1万+

UVa 10892 - LCM Cardinality

Description A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive i...

weixin_30448685的博客 169

PX4 Gazebo仿真进阶:自定义飞机模型和地图的完整指南

本文详细介绍了如何在PX4 Gazebo仿真中自定义飞机模型和地图模型,包括文件架构解析、参数调整指南、地图定制技巧及常见问题解决方案。通过实战步骤和性能优化建议,帮助开发者高效完成复杂场景的飞行控制算法测试。

weixin_29081101的博客 386

uva 10892 - LCM Cardinality(数论)

题目链接:uva 10892 - LCM Cardinality 题目大意:给出l,为说有多少组A,B的最小公约数为l。 解题思路:将L的因子分离出来,因为最大不过几百个,所以可以用o(n^2)暴力枚举一下。 #include #include #include #include using namespace std; const int N = 10

不慌不忙、不急不躁 2206

保姆级教程:手把手教你下载和配置Waymo自动驾驶数据集(附百度网盘链接)

本文提供了一份详细的Waymo自动驾驶数据集下载和配置指南,特别针对国内研究者优化了数据获取方案,包括百度网盘链接和Google Cloud CLI配置。文章还涵盖了环境配置、数据处理实战、可视化分析以及进阶技巧,帮助开发者高效利用这一业界黄金标准数据集进行自动驾驶研究。

weixin_42651281的博客 363

AD17入门简单教程(一)

AD17入门简单教程 我写这篇文章主要是因为最近刚学习完了AD17,想做一下总结,也希望通过自己心得的帮助一些刚入门AD17的小白。 总结一共分为两大部分,包括AD17的下载安装与汉化(文末有详细链接)、工程的创建、元器件库、PCB、走线中的常用命令介绍,文末还附有完整的PCB工程以及讲解视频。 第一部分工程的创建及元器件库常用命令 1.首先在桌面上创建一个文件夹,然后在AD17点击左上角的文件中...

qq_45433195的博客 2万+

UVA697 LA5469 Jack and Jill【数学Ad Hoc】

Jack and Jill went up the hill to fetch a pail of water. Well, they probably need to fetch many pails of water in this problem. The problem is to determine how long it will take Jack and Jill to fetch...

海岛Blog 875

VN5620以太网测试——DoIP配置

CANoe(CAN open environment)VN5620 :是一个紧凑而强大的接口,用于以太网网络的分析、仿真、测试和验证。VN5620 接口支持各种可能的应用。它适用于与其他总线系统、网络参与(例如在模拟和生成帧、测试中的负载和错误)的同步以太网监控。在2021年Vector公司的以太网接口卡VN5610和VN5640设备已经陆续停产,相应被VN5620和VN5650代替。参考文章了解DoIP协议——汽车以太网应用介绍。

诊断协议那些事儿's blog 3009

UVa 10892 LCM Cardinality (分解质因数+数学)

本题挺经典的,sqrt(n)时间复杂度分解质因数。 先看一个公式,数字a=p1^a1*p2^a2*p3^a3.........,b=p1^b1*p2^b2*p3^b3(其中pi为质因数,ai,bi为幂次),那么他们的LCM c=p1^max(a1,b1)*p2^max(a2,b2)..........,同理gcd是取每个质因数幂次最小值。 这样,如果lcm:c确定了,且c=p1^c1*

Baoli1008的专栏 1294

【RH850/U2A】:HSM与APP通信(中断方式)

HSM与APP通信(中断方式)

1993

深度拆解 ‘High-Frequency Trading’ (HFT) 系统:解析如何在 100 纳秒内完成从网卡到 C++ 策略的响应

在100纳秒内完成从网卡到C++策略的响应,这是一项对技术栈每一个层面都进行极限优化的系统工程。它要求我们深入理解计算机体系结构、操作系统、网络协议和C++语言的底层机制。从物理距离的极致缩短,到高性能网卡和内核旁路技术,再到C++代码中每一个字节、每一个CPU周期的精打细算,HFT系统展现了人类对计算速度的永恒追求。这项技术不仅仅应用于金融交易,其背后的低延迟理念和实现方法,如DPDK、无锁编程、硬件加速等,正在逐渐渗透到其他对延迟敏感的领域,例如电信网络、边缘计算和工业自动化。

weixin_41455464的博客 1039

素因子分解&&素因子分解求最大公约数&&素因子分解求最小公倍数

素因子分解 就是把一个数化成

追梦赤子心 1757

从统一入口到运营中枢:全面看懂 SAP for Me 的能力边界、使用方式与项目价值

SAP for Me 是 SAP 推出的统一工作平台,旨在整合原本分散在多个系统中的关键信息与操作。它将许可证管理、系统状态、支持工单、维护合同、产品路线图等核心功能集中到一个界面,为不同角色提供定制化视图。平台包含多个功能模块:Home 作为个性化工作台展示待办事项与风险;Calendar 整合各类维护事件与关键时间节点;Reporting 提供跨域分析与趋势洞察;Finance &amp; Legal 管理订单、发票与合规事项;Portfolio &amp; Products 则展示产品全景与路线图。该

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 121

UVA10892 最小公倍数素因子分解

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1833 A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible p

ACM,再见! 1266

深度学习工具包 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&#39;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 = &quot;R. B. Palm&quot;, title = &quot;Prediction as a candidate for learning deep hierarchical models of data&quot;, year = &quot;2012&quot;,}```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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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 &lt; 0.10, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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 &lt; 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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&lt;0.12, &#39;Too big error&#39;);```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(&#39;state&#39;,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 &lt; 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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 &lt; 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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 &lt; 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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 &lt; 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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 &lt; 0.1, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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 &lt; 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free &quot;Bitdeli Badge&quot;)

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

uva 10892 LCM Cardinality

uva 10892 LCM Cardinality

@fei 484

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

UVa10892 - LCM Cardinality(质因数分解)

简介:给出n,求lcm(a,b)=n的(a,b)对数分析: 首先把n质因子分解: 对于任何一个p,都有max(ka,kb)=k 当ka=k时,kb的取值范围是0~k(共k+1种选择) 当kb=k时,ka的取值范围是0~k(共k+1种选择) 综上所述,针对每一个lcm的质因子,都有2*k+1种方案(ka=kb的情况算一种) 所以 其中1/2是因为只计算a < b的情况,+1是因为要加上a=

Coco_T的博客 632

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

uva10892

此题坑爹。。。我开始以为要用到什么组合公式啊或者什么技巧什么的。。。。 其实 此题就是暴力!!! 你求出lcm的所有因数 ,然后暴力所有的因数。 just this OMG! uva10892  ORG

lyc 973

uva 10892 素因子分解

#include #include const int maxn = 1E5 + 10; const int INF = 0x3f3f3f3f; int visit[maxn], prime[maxn], kase, T, m, n; int getprime() { memset(visit, 0, sizeof(visit)); int cnt = 0; for (long long

Tczxw的专栏 484

uva 10892

试了一下纯暴力 结果过了 无话可说 应该有更好的方法...... /************************************************************************* &gt; Author: xlc2845 &gt; Mail: xlc2845@gmail.com &gt; Created Time: ...

weixin_30699741的博客 152

UVA10892 - LCM Cardinality(分解质因子)

题目链接 题意:输入正整数n,统计有多少对正整数a 思路:分解质因子,然后直接暴力求出对数 代码: #include #include #include #include #include using namespace std; typedef long long ll; const int MAXN = 1000; ll arr[MAXN];

懒人一枚。 1124

UVa 10892

本题我找了下规律然后就结束了 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i,n) for(int i=0;i<(n);i++) #def

qyl916的专栏 545

UVA - 10892 LCM Cardinality (枚举因子)

A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. Forexample 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the

那些年 1003

ACM-分解素因子

在一些数学题目中,经常需要将某个数进行分解,以便于发现一些规律然后进行求解。 首先不得不说的一个定理就是唯一分解定理:

我了个去 4625

LCM的个数 UVa10892

1.题目描述:点击打开链接 2.解题思路:本题要求统计有多少个a,b,使得lcm(a,b)=n,其中n是给定的一个整数。不难发现,这里的a,b一定都是n的约数。根据题目给定的范围,不妨事先计算出所有的约数,。接下来利用二重循环枚举约数即可。注意:由于还要满足a≤b。那么只需要算出不超过sqrt(n)的所有约数即可,剩下的部分可以根据约数的对称性得到。这样的约数肯定不超过1000个,时间可以承受。

Skyline 915

UVA 10892 LCM Cardinality (分解质因数)

题意:给一个数n,让你求他可以是多少组数的最小公倍数。比如12,(1,12),(2,6),(3,4)等的最小公倍数都是12 分析:本题需要用到唯一分解定理 a=p1^a1*p2^a2*p3^a3......... b=p1^b1*p2^b2*p3^b3.........(其中pi为质因数,ai,bi为幂次) 对于他们的最小公倍数 c=p1^c1*p2^c2*p3^c3......... ...

Insist_77的博客 539
上一篇: UVa 10780 Again Prime? No Time. (数论&素因子分解)
下一篇: UVa 11752 The Super Powers (数学)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值