POJ 3100: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;
- }
POJ 3100:Root of the Problem的更多相关文章
- POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!
水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...
- 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 ...
- zoj2818 Root of the Problem 简单数学 开方
Root of the Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Given positive integers B and ...
- zoj 2818 Root of the Problem
Root of the Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Given positive integers B and ...
- 尺取法 POJ 3320 Jessica's Reading Problem
题目传送门 /* 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 */ #include <cstdio> #include <cmath> ...
- POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)
题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...
- POJ 3320 Jessica's Reading Problem 尺取法
Description Jessica's a very lovely girl wooed by lots of boys. Recently she has a problem. The fina ...
- OpenJudge/Poj 1207 The 3n + 1 problem
1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...
- POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)
http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...
随机推荐
- 22Spring基于配置文件的方式配置AOP
直接看代码: package com.cn.spring.aop.impl; //加减乘除的接口类 public interface ArithmeticCalculator { int add(in ...
- JqueryValidate 修改 为根据ID验证
<!--修改validate根据ID验证 --> <script type="text/javascript"> if ($.validator) { $. ...
- 【Kafka问题解决】Connection to xxx could not be established. Broker may not be available.
请检查Kafka的config/server.properties 看看是否有填写 listeners=PLAINTEXT://kafka-host:9092 advertised.listeners ...
- Android : reletive layout
在兄弟的上下左右: android:layout_toRightOf="@id/btn1"/> android:layout_toLeftOf="@id/img1& ...
- js给对象添加属性
obj.prototype = shuxing: shuxing['属性']=值: function Person(){}; var person = new Person(); person.nam ...
- git-svn操作
1.git svn clone --username=chenzheng http://10.0.0.178/repos/trunk/hxqcgf/auto_accessories.admin.h ...
- POJ-3692Kindergarten,求最大独立集!
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Description In a kindergarten, there ar ...
- noip模拟赛 旅行
分析:一个贪心的想法是每次找到根的点权和最大的点进行操作,关键是怎么维护.每次找最大值,修改后会对这条链上每个点的子树上的点造成影响,可以用线段树来维护.找最大值就是区间求最大值嘛,对子树进行操作利用 ...
- Codeforces Round #457 (Div. 2) B
B. Jamie and Binary Sequence (changed after round) time limit per test 2 seconds memory limit per te ...
- POJ 2135_Farm Tour
题意: 从出发点到目的地往返一次,道路i连接着ai号和bi号,长度为ci.同一条路只能走一次,求最小路径长度. 分析: 如果没有往返,那么就是简单的最短路问题.如果规定严格从左到右,那么就是简单的双调 ...