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://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1818 pid=2740">http://acm.hdu.edu.cn/showproblem.php?pid=2740
HDU:
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
题意:
给定整数b和n,求整数a使得a^n最接近b。
代码例如以下:
#include <cstdio>
#include <cmath>
int main()
{
int b, n;
while(~scanf("%d%d",&b,&n))
{
if(b==0 && n==0)
break;
double tt = (double)pow(b,1.0/n);
int t1 = ceil(tt);//向上取整
int t2 = floor(tt);//向下取整
if(b-pow(t2,n)>pow(t1,n)-b)
printf("%d\n",t1);
else
printf("%d\n",t2);
}
return 0;
}
POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)的更多相关文章
- POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)
POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...
- POJ 3652 & ZOJ 2934 & HDU 2721 Persistent Bits(数学 元)
主题链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do? probl ...
- POJ 3654 & ZOJ 2936 & HDU 2723 Electronic Document Security(模拟)
题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- POJ 3653 & ZOJ 2935 & HDU 2722 Here We Go(relians) Again(最短路dijstra)
题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...
- POJ 1325、ZOJ 1364、HDU 1150 Machine Schedule - from lanshui_Yang
Problem Description As we all know, machine scheduling is a very classical problem in computer scien ...
- 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 ...
- POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)
POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for ...
- POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!
水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...
- HDU 4974 A simple water problem(贪心)
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
随机推荐
- Python语法
- SilkTest高级进阶系列10 – bitmap工具bitview
SilkTest 提供了一个bitmap的工具,它可以帮助我们捕捉,比较bitmap文件.该bitmap工具的位置是~/SilkTest/bitview.exe 运行该工具后,你会发现它提供了捕捉控件 ...
- Android Studio Gradle 添加.so 支持文件
近期发展Android Wear 关注商品.官员Demo所有gradle 工程. 当然,我也用eclipse配置一个可行的环境. 问题来了,eclipse,android studio 开发 andr ...
- Visual Studio 2008中FormatX源代码格式化插件
原地址:http://www.cr173.com/html/15492_1.html 我总是对组里的兄弟代码规范性近乎完美的要求,举个简单的例子: 1. 每个方法必须有注释,方法参数详细说明 2. ...
- 图解:如何U盘装Win7系统(傻瓜式装机) + 分区步骤图解(用WIN7自带管理工具)
原地址:http://wenku.baidu.com/link?url=wV2Pfw2IM21u2KmtAcNweSZRwpXRuKAVAS29dS4aWGEpMtFdDlzZvixCgsvBxIm- ...
- 在qt中用tcp传输xml消息
在qt中用tcp传输xml消息 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN7 开发环境:Qt5 3.1.2 说明: 在tcp上 ...
- Hbase经常使用命令
hbase shell命令的使用 再使用hbase 命令之前先检查一下hbase是否执行正常 hadoop@Master:/usr/hbase/bin$ jps 2640 HMaster 27170 ...
- select下拉菜单反显不可改动,且submit能够提交数据
首先通过后台funcA()将下拉菜单反显不可改动的数据response到disable.jsp页面,disable.jsp: <script> var data1=${result.obj ...
- https原理及tomcat配置https方法
一. 什么是HTTPS 在说HTTPS之前先说说什么是HTTP,HTTP就是我们平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不 ...
- hdu1059(多重背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1059 题意 : 按顺序读入一些列数,所对应的序列代表价值,数值代表个数(如a[5]=6 ,代表价值为五 ...