zoj2818 Root of the Problem 简单数学 开方
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比较。
#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 简单数学 开方的更多相关文章
- zoj 2818 Root of the Problem(数学思维题)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2818 题目描述: Given positive integer ...
- HDU-4627 The Unsolvable Problem 简单数学
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4627 对n除个2,然后考虑下奇偶... //STATUS:C++_AC_15MS_228KB #inc ...
- HDU 5073 Galaxy (2014 Anshan D简单数学)
HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...
- 洛谷试炼场-简单数学问题-P1403 [AHOI2005]-因数
洛谷试炼场-简单数学问题 P1403 [AHOI2005]约数研究 Description 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机"Samuel I ...
- 洛谷试炼场-简单数学问题-P1045 麦森数-高精度快速幂
洛谷试炼场-简单数学问题 B--P1045 麦森数 Description 形如2^P−1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果PP是个素数,2^P-1 不一定也是素数.到19 ...
- 洛谷试炼场-简单数学问题-P1088 火星人
洛谷试炼场-简单数学问题 A--P1088 火星人 Description 人类终于登上了火星的土地并且见到了神秘的火星人.人类和火星人都无法理解对方的语言,但是我们的科学家发明了一种用数字交流的方法 ...
- zoj 2818 Root of the Problem
Root of the Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Given positive integers B and ...
- POJ 3100:Root of the Problem
Root of the Problem Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12060 Accepted: 6 ...
- POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!
水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...
随机推荐
- zookeeper简单介绍
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt193 ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系 ...
- javaScript数组去重方法
在JAvascript平时项目开发中经常会用到数组去重的操作.这时候就要用到JS数组去重的方法了. demo1: 第一种:JS数组去重操作方法是利用遍历原数组,利用数组的indexOf()方法来来判断 ...
- django源码解析一(请求处理流程)
1.我们都知道WSGI是一个规范,规范了server和application之间通信的一些约束,server端在监听到请求之后,会把请求转给application去处理,他们之间关联起来的桥梁是一个e ...
- JAVA基础-集合(一)
一.结构 Collection接口为一些单列集合的根接口,其常用子接口为List接口.Set接口.List接口常用实现子类为ArrayList(数组)LinkedList(链表).Set接口常用实现子 ...
- 沙盒单机网站代表-Steam【推荐】
Steam平台是Valve公司聘请BitTorrent(BT下载)发明者布拉姆·科恩亲自开发设计的游戏平台. Steam平台目前是一款全球最大的综合性数字发行平台.玩家可以在该平台购买.下载.讨论.上 ...
- web程序员标准环境之DreamWeaver【推荐】
Adobe Dreamweaver,简称"DW",中文名称 "梦想编织者",是美国MACROMEDIA公司开发的集网页制作和管理网站于一身的所见即所得网页编辑器 ...
- vmware 遇到 “无法打开内核设备 \\.\Global\vmx86” 解决
问题描述:vmware没有正常关闭,再次打开使用时蓝屏,在安全模式下再次打开不会蓝屏,但提示"无法打开内核设备 \.\Global\vmx86: 系统找不到指定的文件,你想要安装VMware ...
- 必应词典--英语学习APP案例分析
一.调研,评测 1.个人上手体验 这还是第一次听说必应词典,只能说知名度有待提高啊.首先,下载打开必应词典的第一感觉就是不够美观,个人感觉不论图标还是界面的美感都不足,既繁琐有简洁,给人的最直观感受就 ...
- 团队作业8——第二次项目冲刺(Beta阶段)5.22
1.当天站立式会议照片 会议内容: ①:检查总结上次任务完成情况 ②:安排本次任务的分工 ③:反思前三次自己的不足 ④:协商解决代码进度.成员投入时间等问题 2.每个人的工作 工作中遇到的困难: 代码 ...
- Sudoku Generator
Sudoku 算法 标签(空格分隔): 软工实践 设想:通过第一行,来生成2, 3行的排列,再通过1 - 3 生成4 - 6排列. 2 3 行的生成由上一行生成 公式为$grid[i][j] = gr ...