zoj2818 Root of the Problem 简单数学 开方
来源:互联网 发布:淘宝被恶意差评怎么办 编辑:程序博客网 时间:2024/06/05 20:26
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 35 3
27 3
750 5
1000 5
2000 5
3000 5
1000000 5
0 01
2
3
4
4
4
5
16
Source: Mid-Central USA 2006
第一思路:二分找最小k,k^m<=n,然后和(k+1)^m比较。
#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 简单数学 开方
- Root of the Problem
- POJ 3100 Root of the Problem(简单题)
- HDU ACM 2740 Root of the Problem 简单数学题
- 1394. Root of the Problem
- TJU Root of the Problem
- Root of the Problem-3100
- 1394. Root of the Problem
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
- POJ 3100 Root of the Problem
- sicily 1394 Root of the Problem
- zoj 2818 Root of the Problem
- Sicily 1394. Root of the Problem
- poj 3100 Root of the Problem
- POJ 3100 Root of the Problem (水题)
- Sicily 1394. Root of the Problem
- POJ 3100:Root of the Problem
- POJ 3100 Root of the Problem G++
- Stockbroker Grapevine
- [jzoj]1261. 数字游戏(搜索+剪枝)
- Firefox安装selenium自动化测试教程
- hdu1176——免费馅饼
- 平方根的C语言实现(一) —— 浮点数的存储
- zoj2818 Root of the Problem 简单数学 开方
- redis关闭服务失败报错:(error) ERR Errors trying to SHUTDOWN. Check logs.
- 1010. Radix (25)
- C#学习笔记壹---字符串处理技术(1)
- HDU 6015 Gameia【博弈】
- nginx搭建(基于source code)
- 迷宫大门
- 机器学习笔试题4
- 单链表