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.

 #include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main(){
double b, n;
while(cin >> b >> n){
if(b == && n == )
break;
//pow:double pow(double, double)
int a = (int)pow(b, / n);//直接取整,不是四舍五入 ,pow(a, n) < b
if(b - pow(a, n) < pow(a + , n) - b)
cout << a << endl;
else
cout << a + << endl;
}
return ;
}
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

zoj 2818 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. poj 3100 (zoj 2818)||ZOJ 2829 ||ZOJ 1938 (poj 2249)

    水题三题: 1.给你B和N,求个整数A使得A^n最接近B 2. 输出第N个能被3或者5整除的数 3.给你整数n和k,让你求组合数c(n,k) 1.poj 3100 (zoj 2818) Root of ...

  3. zoj2818 Root of the Problem 简单数学 开方

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

  4. POJ 3100:Root of the Problem

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

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

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

  6. POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

    题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...

  7. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  8. ZOJ 3686 A Simple Tree Problem(线段树)

    Description Given a rooted tree, each node has a boolean (0 or 1) labeled on it. Initially, all the ...

  9. zoj 3686 A Simple Tree Problem (线段树)

    Solution: 根据树的遍历道的时间给树的节点编号,记录下进入节点和退出节点的时间.这个时间区间覆盖了这个节点的所有子树,可以当做连续的区间利用线段树进行操作. /* 线段树 */ #pragma ...

随机推荐

  1. 130 Surrounded Regions 被围绕的区域

    给定一个二维的矩阵,包含 'X' 和 'O'(字母 O), 找到所有被 'X' 围绕的区域.并将区域里所有 'O'用 'X' 填充.例如,X X X XX O O XX X O XX O X X运行你 ...

  2. Nginx缓存[proxy cache、memcache]

    nginx自带缓存 nginx自己有单独的进程来对磁盘上的缓存文件进行扫描,在内存中建立缓存索引.并且有管理进程来对缓存进行过期判断,更新等操作 定义:只能在http段中使用 proxy_cache_ ...

  3. RAID基础

    磁盘类型 类型 IDE Integrated Drive Electronics SATA Srial ATA SCSI Small Computer System Interface FC Fibe ...

  4. C++ <string> 里面的size_type

    string::size_type string的 str.size() 返回值是一个unsigned,实际上返回的是size_type类型的值. string类和其他的大多数标准库类型都定义了几套配 ...

  5. CentOS Linux下MySQL 5.1.x的安装、优化和安全配置

    下载页面:http://dev.mysql.com/downloads/mysql/5.1.html#downloads 到页面底部,找到Source downloads,这个是源码版本,下载第1个T ...

  6. archsummit_bj2016

    http://bj2016.archsummit.com/schedule 大会日程 2016年12月02日,星期五 7:45-9:00 签到 8:45-9:00 开始入场 9:00-9:30 开场致 ...

  7. 谈谈对Android中的消息机制的理解

    Android中的消息机制主要由Handler.MessageQueue.Looper三个类组成,他们的主要作用是 Handler负责发送.处理Message MessageQueue负责维护Mess ...

  8. HYSBZ 1208 宠物收养所 (Splay树)

    题意:一家宠物收养所负责处理领养者与遗弃宠物业务,有人来领宠物,则领一只最理想的.若没有宠物了,领养者们就得等到宠物来,宠物一来立刻送给其中一个等待者.如果有两个理想的选择,则选择那个值较小的.收养所 ...

  9. 洛谷 U10223 Cx大帝远征埃及

    题目背景 众所周知,Cx是一个宇宙大犇.Cx能文善武,一直在为大一统的实现而努力奋斗着.Cx将调用他的精锐军队,一个精锐士兵最多可以战胜十个埃及士兵.同时Cx是个爱才的人,他想要制定一份能使在占领埃及 ...

  10. 原创:E325: ATTENTION vim超完整超给力的问题与解决方法

    又到了老葵花哥哥开课的时间 这是给大家提供一个企业常见的错误 我相信大家生活还编程中会长期使用接触这个错误 这里我们经常用的两个选项 (E)dit any way 编辑原来的文件,忽略刚刚做的修改 ( ...