二分法+高精度——Poj 2109 Power of Cryptography(double型开n次方的方法通过的原因)

POJ2109-Power of Cryptography 北大POJ2109-Power of Cryptography 解题报告+AC代码 立即下载

Power of Cryptography
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 14584 Accepted: 7412

Description

Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in this area has resulted in the practical use of results from number theory and other branches of mathematics once considered to be only of theoretical interest. 
This problem involves the efficient computation of integer roots of numbers. 
Given an integer n>=1 and an integer p>= 1 you have to write a program that determines the n th positive root of p. In this problem, given such integers n and p, p will always be of the form k to the nth. power, for an integer k (this integer is what your program must find).

Input

The input consists of a sequence of integer pairs n and p with each integer on a line by itself. For all such pairs 1<=n<= 200, 1<=p<10101 and there exists an integer k, 1<=k<=109 such that kn = p.

Output

For each integer pair n and p the value k should be printed, i.e., the number k such that k n =p.

Sample Input

2 16
3 27
7 4357186184021382204544

Sample Output

4
3
1234


如果你只是想知道为什么double型开n次方法通过的原因,请跳过此部分。

题目大意:

求一个整数k,使得k满足kn=p。

思路:

由于p的值很大,超出了基本数据类型所表示的范围,所以采用大数乘法来计算kn,当k­n=p时,得出结果(不知道能不能大数开n次方…)。那k值应该如何取呢?根据n和p的关系是可以确定出k的位数的,例如:n=7,p=4357186184021382204544,p的位数为22,用22/7的结果向上取整,得到4,即为k的位数,也就是说k的取值范围是1000~9999。在这个范围内进行二分查找,就可以找到满足条件的k值。(这狗屎题目中说“there exists an integer k, 1<=k<=109 , such that kn = p.”,其实…逗你玩!)

#include <stdio.h>
#include <string.h>
#include <math.h>

#define LENGTH         110
#define LAST LENGTH-2
#define GREATER        1
#define EQUAL          0
#define LESS          -1

//大整数相乘
char* IntegerMultiplication(const char *a, const char *b, char *product)
{
	int i, j, k = LAST, first, value, temp[LENGTH];
	memset(temp, 0, sizeof(temp));
	for (i = strlen(a)-1; i >= 0; i--)
	{
		first = k--;
		value = a[i] - '0';
		for (j = strlen(b)-1; j >= 0; j--)
		{
			temp[first--] += value * (b[j] - '0');
		}
	}
	for (i = LAST; i >= first; i--)
	{
		product[i] = temp[i] % 10 + '0';
		temp[i-1] += temp[i] / 10;
	}
	while (product[first] == '0' && first < LAST)
	{
		first++;
	}
	return &product[first];
}

//比较两个字符串所表示数值的大小
int Compare(char *numA, char *numB)
{
	//去除前导'0'
	for (; *numA == '0'; numA++);
	for (; *numB == '0'; numB++);
	int lenNumA = strlen(numA);
	int lenNumB = strlen(numB);
	if (lenNumA == lenNumB)
	{
		return strcmp(numA, numB);
	}
	if (lenNumA > lenNumB)
	{
		return GREATER;
	}
	return LESS;
}

//求base^exp,结果存放在res中,pRes指向结果的首位数字的位置
char* Power(char *base, int exp, char *res)
{
	res[LAST] = '1';
	char *pRes = &res[LAST], *temp = base;
	while (exp != 0)
	{
		if (exp % 2 == 1)
		{
			pRes = IntegerMultiplication(base, pRes, res);
		}
		exp /= 2;
		if (exp != 0)
		{
			base = IntegerMultiplication(base, base, temp);
		}
	}
	return pRes;
}

int main(void)
{
	char p[LENGTH], res[LENGTH], cMid[LENGTH];
	unsigned int n, lenP, lenRoot, i, min, max, mid;
	
	while (scanf("%d %s", &n, &p) != EOF)
	{
		//根据n和p的倍数关系,得到k的范围的min值和max值
		lenP = strlen(p);
		lenRoot = (int)ceil((double)lenP / n);
		for (i = 1, min = 1; i < lenRoot; i++)
		{
			min *= 10;
		}
		for (i = 1, max = 9; i < lenRoot; i++)
		{
			max *= 10;
			max += 9;
		}

		//二分法寻找k值
		bool finish = false;
		while (!finish)
		{
			mid = (min + max) / 2;
			if (min >= max)
			{
				break;
			}
			sprintf(cMid, "%d", mid);
			memset(res, 0, sizeof(res));
			switch (Compare(Power(cMid, n, res), p))
			{
			case LESS: min = mid + 1; break;
			case EQUAL: finish = true; break;
			case GREATER: max = mid - 1; break;
			default: break;
			}
		}
		//由于题目所给数据会有不满足k^n=p的情况
		//下面是为了得到一个最大的k,满足k^n<=p
		sprintf(cMid, "%d", mid);
		if (Compare(Power(cMid, n, res), p) == GREATER)
		{
			mid--;
		}
		printf("%d\n", mid);
	}
	return 0;
}

double型开n次方的方法通过的原因

下面这段程序也是可以通过此题的。

#include<stdio.h>
#include<math.h>

int main(void)
{
	double n, p;
	while(scanf("%lf%lf", &n, &p) != EOF)
	{
		printf("%.0lf\n", pow(p, 1/n));
	}
	return 0;
}

首先,题目中的数据强度并不弱,这一点确实如题目中所说:“For all such pairs 1<=n<= 200, 1<=p<10101,所以,double型是不能精确地表示出所给数据,但是却能表示出一个近似值。

当向double型变量中存入

4357186184021382204544

然后再输出,得到的是

4357186184021382000000

后六位的值变为了0,这一点和int型变量是有很大区别的。也就是说当存入double型变量的值超出了它的精度表示范围时,将低位的数据截断。(关于浮点数在计算机中的表示方法,百度吧…讲的蛮清楚的。)

在本题中,如果测试数据为:

7     4357186184021382204544

实际上所处理数据是:

7     4357186184021382000000

拿4357186184021382000000开7次方的结果自然就是1234。

为什么不是1233或者1235呢?

12337=4332529576639313702577

12347=4357186184021382204544

12357=4381962969567270546875

可以看出在double型所能表示的精度范围内,它们三个值已经不同了。

所以,此题中的测试数据也都是类似于上述情况,所以才能使用double型开n次方的方法。

STM32入门教程:自动门控制 通过这个简单的示例,我们展示了如何使用STM32微控制器来实现一个简单的自动门控制系统。如果有物体靠近门口,我们会改变doorState的值,并使用controlServoMotor函数来控制舵机电机的转动。具体的引脚连接可以根据您的具体硬件来定,例如将红外传感器的输出引脚连接到GPIOA_PIN0引脚。同样,具体的引脚连接可以根据您的具体硬件来定,例如将舵机的控制引脚连接到GPIOA_PIN1引脚。首先,我们需要包含必要的库文件和引用。然后,我们需要定义一些函数来处理红外传感器的输入和舵机电机的输出。 阅读详情

相关推荐

LVGL8.x 实体按键与Keypad驱动的无缝对接实战

本文详细解析了LVGL8.x中实体按键与Keypad驱动的两种对接方案:坐标映射的Button方式与事件驱动的Keypad方式。重点阐述了如何模块化裁剪lv_port_indev.c模板文件,并深入讲解了Keypad驱动与Group焦点管理系统的核心协作机制,为无触摸屏的嵌入式设备提供流畅的UI交互解决方案。

weixin_29164497的博客 446

Power of Cryptography

//只用一行核心代码就可以过的天坑题目............= = 题目: Description Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in thi...

weixin_30483697的博客 104

Nvivo12新手避坑指南:从安装到编码的完整流程(附实战案例)

本文为Nvivo12新手提供了从软件安装、初始设置到数据导入和编码分析的完整避坑指南。通过一个“校园欺凌现象的学生访谈研究”实战案例,详细拆解了处理中文文本、创建项目结构、执行手动编码及高级查询等关键步骤,帮助研究者避开常见错误,快速上手并高效完成质性数据分析。

resnet7explorer的博客 315

贪心——Power of Cryptography

Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 18080   Accepted: 9124 Description Current work in cryptography involves (among other t

空白页 639

【Tableau】解决订阅报表PDF中文显示为乱码(方框)问题

一、问题描述 在tableau server网页端报表中文字符能正常显示,但在订阅后发送到邮箱时,以图片格式呈现的内容中中文字符显示为方框。 网页端报表能正常显示中文字符: 邮件中的报表不能正常显示中文字符: 二、问题分析 网页端字符显示情况是由html编码决定的,而tableau生成图片时是通过所部署的服务器的字体文件显示字体。因此可能是由于Linux服务器缺失相关的字体文件导致网页端选择的中文字体在服务器上缺失对应的字体文件导致的。则考虑在服务器引入对应的字体文件。 三、问题解决 1、查看服务器现有

why_not_study的博客 2833

目标检测 | R-CNN、Fast R-CNN与Faster R-CNN理论讲解

目标检测:R-CNN、Fast R-CNN与Faster R-CNN理论讲解,根据B站up霹雳吧啦Wz总结。此文章包含R-CNN算法原理讲解、Fast R-CNN算法原理讲解、Faster R-CNN原理讲解、目标检测评价指标介绍与特征金字塔网络FPN讲解。

houjingchuan的博客 9566

分巧克力(二分) JAVA题解

儿童节那天有KK位小朋友到小明家做客。 小明拿出了珍藏的巧克力招待小朋友们。 小明一共有NN块巧克力,其中第ii块是Hi×WiHi×Wi的方格组成的长方形。 为了公平起见,小明需要从这NN块巧克力中切出KK块巧克力分给小朋友们。 切出的巧克力需要满足: 形状是正方形,边长是整数 大小相同 例如一块6×56×5的巧克力可以切出66块2×22×2的巧克力...

weixin_41988889的博客 804

自动驾驶必备:5分钟搞懂gPTP如何实现μs级时间同步(附开源代码)

本文深入解析了gPTP协议在自动驾驶系统中实现微秒级时间同步的核心机制与工程实践。针对多传感器融合与跨域协同的严苛需求,文章拆解了gPTP的频率同步、对等延迟测量与时间偏移校正三步流程,并提供了基于linuxptp和AVnu gPTP两大开源代码库的实战配置指南与性能评估方法,助力开发者构建高精度、高可靠的车载时间同步网络。

weixin_29211309的博客 167

POJ2109 高精度(含大数开方)+二分

1 高精度(含大数开方)+二分 一个技巧和三点注意: 技巧:假设k^n=p;(k的n次方),那么p的位数/n得到的是k的位数!例如:n=7,p=4357186184021382204544,p的位数为22,用22/7的结果向上取整,得到4,即为k的位数,也就是说k的取值范围是1000~9999。(引自code_pang)不利用这一点,高精度+直接二分,也会超时。用这一个技巧合理缩小二分的范围。

他的博客 2396

rk3588 适配以太网(百兆)

虽然 RK3588 的 GMAC 控制器原生支持千兆速率(10/100/1000 Mbps),但在某些工业控制、物联网网关或成本敏感型硬件设计中,开发者会选择将其配置为 百兆以太网(Fast Ethernet) 模式。

weixin_35723192的博客 218

OpenClaw进阶实战(二十五):抖音企业号——私信回复与视频评论分析

摘要:本文介绍抖音企业号自动化运营方案,突破抖音强风控体系的技术挑战。针对内容生产、私信互动和账号矩阵三大场景,提出混合架构解决方案: 私信自动化:结合关键词触发与随机延迟(45秒±15),实现拟人化回复,支持价格咨询/商务合作等高优先级消息识别 混合技术栈:官方API(合规)+真机RPA(覆盖长尾需求)+AI辅助生成(脚本→剪辑→发布闭环) 安全策略:通过设备指纹模拟、行为间隔随机化和内容差异化处理规避风控,提供每日200条的安全操作阈值。配套OpenClaw技能实现一键部署,包含cookie配置、回复规

PeterPan的博客 142

贪心算法 | Poj2109

题目:http://poj.org/problem?id=2109 Description Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in this area

Allan的专栏 2195

基于聚类特征工程的水果销量预测:聚类算法对比与多模型评估

水果销量预测研究:聚类分群与多模型对比 摘要 本研究提出了一种融合聚类分析与机器学习的水果销量预测方法。基于包含12个维度的销售数据集,首先采用K-Means、BIRCH和DBSCAN三种聚类算法对水果品类进行分群,通过轮廓系数等指标评估显示BIRCH算法表现最优(0.387)。随后针对不同群组构建差异化特征工程,并比较XGBoost、LightGBM和LSTM三种预测模型性能。实验结果表明:基于聚类特征工程的LightGBM模型预测效果最佳(RMSE=2.34,R²=0.87).

huanghm88的专栏 137

(转) 二分法+高精度——Poj 2109 Power of Cryptography(double型开n次方的方法通过的原因)

Power of Cryptography Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 14584   Accepted: 7412 Description Current work in cryptography involves (among o

戴某某 415

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

POJ 2109 Power of Cryptography

地址:http://poj.org/problem?id=2109 题意:求lognp 思路:纯纯卡bug,指数的倒数就是开n次方 #include #include using namespace std; int main(void) { double n,p; while(cin>>n>>p) cout<<pow(p,1.0/n)<<endl; return

629

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

POJ-2109 Power of Cryptography (Double)

POJ-2109 Power of Cryptography (Double) 题意:给定n,pn,pn,p已知kn=pk^n=pkn=p,求kkk,1≤p≤101011\le p\le10^{101}1≤p≤10101。 思路:正解应该是二分+++高精度快速幂。 但是本题可以有个更快解法:用doubledoubledouble,−1.7e308≤double≤1.7e308-1.7e^{308}\le double\le 1.7e^{308}−1.7e308≤double≤1.7e308,然后调用pow(

Harris-H的博客 543

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

POJ 2109 Power of Cryptography【高精度+二分 Or double水过~~】

题目链接: http://poj.org/problem?id=2109 参考: http://blog.youkuaiyun.com/code_pang/article/details/8263971 题意: 给定n,p,求k使得kn=p(1≤n≤200, 1≤p<10101, 1≤k≤109) 分析: 高精度+二分~~ k的位数为p的位数除以n的向上...

An55511的博客 214

POJ2109 Power of Cryptography (高精度+二分) (可以double水過去)

Description Current work in cryptography involves (among other things) large prime numbers and computing powers of numbers among these primes. Work in this area has resulted in the practical use of r

clogos的专栏 518

POJ 2109 Power of Cryptography 数学题 double和float精度和范围

Power of Cryptography Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21354 Accepted: 10799 DescriptionCurrent work in cryptography involves (among other things) large prime nu

smilesundream的博客 557

poj 2109 Power of Cryptography

 http://poj.org/problem?id=2109 求一个整数k,使得k满足kn=p。 一般思路   :  二分+高精度算法 其他技巧:求指数k除了使用对数log,还能使用指数的倒数开n次方 ,用到了pow函数。即pow(p,1/n); PS  :    pow(double,double) 并且返回double值。 double类型虽然能表示10^(-307)   ~

Song 638

POJ 2109 Power of Cryptography(简单计算)

原题地址:http://poj.org/problem?id=2109 已知kn=p,给定n和p,求k。 解题思路不知道目录里这道题为什么被分到贪心算法??? 刚看到题目,被题目的p的范围10^101吓到,以为要用高精度整数+二分来求p的n次根。 但是注意到double的数值范围是[-1.7*10^308, +1.7*10^308],远大于10^101;double有效精度为15-16位,题

Lecholin的博客 323
上一篇: 补码的代数解释
下一篇: 二分查找+大整数加法——Poj 2413 How many Fibs?
庞老板
博客等级 码龄15年 127粉丝 66原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

打赏作者

庞老板

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

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

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

打赏作者

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

抵扣说明:

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

余额充值