Root of the Problem


Time Limit:
2 Seconds      Memory Limit:
65536 KB


Given positive integers B and N, find an integer A such that AN is as close as possible to B. (The result A is an approximation to the Nth root
of B.) Note that AN may be less than, equal to, or greater than B.

Input: The input consists of one or more pairs of values for B and N. Each pair appears on a single line, delimited by a single space. A line specifying the value zero for
both B and N marks the end of the input. The value of B will be in the range 1 to 1,000,000 (inclusive), and the value of N will be in the range 1 to 9 (inclusive).

Output: For each pair B and N in the input, output A as defined above on a line by itself.

Example Input: Example Output:
4 3

5 3

27 3

750 5

1000 5

2000 5

3000 5

1000000 5

0 0
1

2

3

4

4

4

5

16

Source: Mid-Central USA 2006





第一思路:二分找最小k,k^m<=n,然后和(k+1)^m比较。



第二思路:我们都知道n的m次方为pow(n,m)——精确值,则n开m次方为pow(n,1/m)——近似值(有时会把结果拿回去验证一遍)。当然这个函数适用于小数据,int范围就最好。


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std; int main()
{
int n,m,k;
while(cin>>n>>m){
if(!n&&!m) return 0;
k=pow(n,(double)1/m);
if(pow(k+1,m)-n<n-pow(k,m)) k++;//求靠近的一个
cout<<k<<endl;
}
return 0;
}

zoj2818 Root of the Problem 简单数学 开方的更多相关文章

  1. zoj 2818 Root of the Problem(数学思维题)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 题目描述: Given positive integer ...

  2. HDU-4627 The Unsolvable Problem 简单数学

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 对n除个2,然后考虑下奇偶... //STATUS:C++_AC_15MS_228KB #inc ...

  3. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  4. 洛谷试炼场-简单数学问题-P1403 [AHOI2005]-因数

    洛谷试炼场-简单数学问题 P1403 [AHOI2005]约数研究 Description 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机"Samuel I ...

  5. 洛谷试炼场-简单数学问题-P1045 麦森数-高精度快速幂

    洛谷试炼场-简单数学问题 B--P1045 麦森数 Description 形如2^P−1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果PP是个素数,2^P-1 不一定也是素数.到19 ...

  6. 洛谷试炼场-简单数学问题-P1088 火星人

    洛谷试炼场-简单数学问题 A--P1088 火星人 Description 人类终于登上了火星的土地并且见到了神秘的火星人.人类和火星人都无法理解对方的语言,但是我们的科学家发明了一种用数字交流的方法 ...

  7. zoj 2818 Root of the Problem

    Root of the Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB Given positive integers B and ...

  8. POJ 3100:Root of the Problem

    Root of the Problem Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12060   Accepted: 6 ...

  9. POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!

    水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...

随机推荐

  1. Centos6.6下安装Python3.5

    centos6.6自带的Python2.6,如果想要安装新版本的Python例如Python2.7+或者Python3.5,不能够用yum安装,那么只能从源码编译安装. Step 1: 安装依赖库和编 ...

  2. hdu 3549最大流Ford-Fulkerson算法

    Ford-Fulkerson算法 戳戳http://www.cnblogs.com/luweiseu/archive/2012/07/14/2591573.html Ford-Fulkerson方法依 ...

  3. poj3249 拓扑排序+DP

    题意:给出一个有向无环图,每个顶点都有一个权值.求一条从入度为0的顶点到出度为0的顶点的一条路径,路径上所有顶点权值和最大. 思路:因为是无环图,则对于每个点经过的路径求其最大权值有,dp[i]=ma ...

  4. 【★】致全球第一批全帧3D游戏!

    图一 游戏片头 致逝去的青春记忆. 好久没人玩Ballance了吧,贴吧里貌似早已冷掉了. 作为一款经典游戏,Ballance的宣传却做得不到位,官方的介绍甚至没能展现出它的全部诱人之处.所以笔者决 ...

  5. 转:【Java并发编程】之二十二:并发新特性—障碍器CyclicBarrier(含代码)

    转载请注明出处:http://blog.csdn.net/ns_code/article/details/17512983 CyclicBarrier(又叫障碍器)同样是Java5中加入的新特性,使用 ...

  6. 结对编程1-四则运算(基于GUI)

    林晓芳201421123092.陈惠201421123096 coding 地址:https://git.coding.net/lianlian/92.96.1.git 一.题目描述 我们在个人作业1 ...

  7. GUI(国际象棋棋盘)

    package com.niit.javagui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridB ...

  8. 201521123001《Java程序设计》第5周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 1.2 可选:使用常规方法总结其他上课内容. 答:关于接口: 1.接口是一种抽象,抽取出了共同行为: 2.能够更加清晰地把系统 ...

  9. python3中的一些小改动

    Python 3.3中使用print是必须要括号因为在python3以上的版本中print不再是一条命令而是一个函数了.

  10. pygame 弹力球及其变速的实现

    期望: 1.球体接触到框体后反弹 2.设置速度按键,按下后改变球体速度.颜色状态 具体实现: import pygame from pygame.locals import * import sys, ...