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

Description

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.

Sample Input

4 3
5 3
27 3
750 5
1000 5
2000 5
3000 5
1000000 5
0 0

Sample Output

1
2
3
4
4
4
5
16

Source

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include <cstdio>
#include <cstdlib>
#include <cmath>
int main()
{
int min, tmp;
int n, b;
float right;
int low, high;
while (scanf("%d%d", &b, &n), n != 0 || b != 0)
{
if (n == 1 || b == 1)
{
printf("%d\n", b);
continue;
}
right = pow(b, 1.0 / n);
low = (int)right;
high = (int)(right + 0.9999);
min = b - pow(low, n);
tmp = pow(high, n) - b;
if (tmp < min)printf("%d\n", high);
else printf("%d\n", low);
}
return 0;
}

最新文章

  1. PyQt4入门学习笔记(四)
  2. Go-Agent部署与FQ教程(2016-10-28)
  3. js 处理 html 标签转义 处理json中含有的ascii 编码
  4. 比较下OceanBase的选举协议和Raft的选举协议的区别
  5. Javascript中二级联动
  6. 七,WPF的元素绑定
  7. 从汇编看c++的虚拟继承以及其内存布局(一)
  8. NET中小型企业项目开发框架系列(一个)
  9. sql 查看语句的性能
  10. SQLsever 复制一行内容到本表
  11. rhev 虚拟化
  12. mysqldump导出多个数据库
  13. Socket详解-Linux Socket编程(不限Linux)
  14. Infiniband基本知识
  15. 三分 - HNU 13409 Flowers
  16. xz文件的解压缩
  17. iOS倒计时
  18. laravel开发环境部署遇到的问题和个人感受
  19. bzoj 4428: [Nwerc2015]Debugging调试
  20. 算法笔记_050:硬币收集问题(Java)

热门文章

  1. 12.Spring通过FactoryBean配置Bean
  2. LeetCode(4)Median of Two Sorted Arrays
  3. allegro学习--区域约束
  4. QueryParser
  5. MySQL MGR源码分析2 - 从start group_replication看MGR代码框架
  6. python 爬虫示例,方便日后参考
  7. JavaEE JDBC 补充注意点
  8. 2018/2/17 SpringCloud的一个简单小介绍
  9. codevs4439 YJQ Requires Food
  10. Thinkphp5.0 的使用模型Model添加数据