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 洪水!!!
水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...
随机推荐
- vSphere笔记01~02
Vmware vsphere 虚拟化 云和大数据的底层!!!! 分类 1.开源:openstack:Linux:难(无图形化) nosqleasystack公司 2.企业版本:vsphere sdn! ...
- 避免subList/subString陷阱
避免subList/subString陷阱 java.util.List 接口提供了一个实例方法 List<E> subList(int fromIndex, int toIndex), ...
- 201521123025《JAVA程序设计》第6周学习总结
1. 本章学习总结 2. 书面作业 Q1.clone方法 1.1Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注意什么? 要克隆对象要覆盖clon ...
- 201521123038 《Java程序设计》 第一周学习总结
201521123038 <Java程序设计> 第一周学习总结 1.本章学习总结 本周已掌握Java配置,初步认识Java运行软件和基本语法. Java语言语法和C语言基本类似,部分不同. ...
- java课程设计--WeTalk(201521123072秦贞一)
在线群聊系统 1,团队课程设计博客链接 http://www.cnblogs.com/slickghost/p/7018105.html 个人负责模块或任务说明 负责模块:界面设计与实现 2,自己的代 ...
- 201521123073 《Java程序设计》第14周学习总结
14周-数据库 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 2. 书面作业 1. MySQL数据库基本操作 建立数据库,将自己的姓名.学号作为一条记录插入. ...
- 201521123099 《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1. ...
- 第二部分----CSS的基础语法
PART-1 CSS的基础常识 一.什么是CSS? W3C标准中,倡导有3:其一为内容与表现分离,其二为内容与行为分离,其三为内容结构的语义化.其倡导中第一条的"表现"指的便可以说 ...
- web前端 学习线路
1. 前言 大约在几个月之前,让我看完了<webkit技术内幕>这本书的时候,突然有了一个想法.想把整个web前端开发所需要的知识都之中在一个视图中,形成一个完整的web前端知识体系,目的 ...
- java.lang.IllegalArgumentException: node to traverse cannot be null!
查看HQL的语句是否写错了,是否有在From后面加空格.我就是没有加空格报了错误! return sessionFactory.getCurrentSession().createQuery(&quo ...