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的更多相关文章

  1. POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!

    水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...

  2. 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 ...

  3. zoj2818 Root of the Problem 简单数学 开方

    Root of the Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB Given positive integers B and ...

  4. zoj 2818 Root of the Problem

    Root of the Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB Given positive integers B and ...

  5. 尺取法 POJ 3320 Jessica's Reading Problem

    题目传送门 /* 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 */ #include <cstdio> #include <cmath> ...

  6. POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

    题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...

  7. 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 ...

  8. OpenJudge/Poj 1207 The 3n + 1 problem

    1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...

  9. POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)

    http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...

随机推荐

  1. 题解 洛谷P1903/BZOJ2120【[国家集训队]数颜色 / 维护队列】

    对于不会树套树.主席树的本蒟蒻,还是老老实实的用莫队做吧.... 其实这题跟普通莫队差不了多远,无非就是有了一个时间,当我们按正常流程排完序后,按照基本的莫队来,做莫队时每次循环对于这一次操作,我们在 ...

  2. [kuangbin带你飞]专题四 最短路练习

    对于最短路,我主要使用的就是dijkstra,Floyd,SPFA这三个算法.先来介绍一下这三个算法. 1. dijkstra算法.它适用于边权为正的情况,它是单源最短路,就是从单个源点出发到所有的结 ...

  3. 使用requests+BeaBeautiful Soup爬取妹子图图片

    1. Requests:让 HTTP 服务人类 Requests 继承了urllib2的所有特性.Requests支持HTTP连接保持和连接池,支持使用cookie保持会话,支持文件上传,支持自动确定 ...

  4. 利用Merge into 改写Update SQL 一例

    前言 客户说,生产系统最近CPU使用率经常达到100%,请DBA帮忙调查一下. 根据客户提供的情况描述及对应时间段,我导出AWR,发现如下问题: 11v41vaj06pjd :每次执行消耗2,378, ...

  5. laravel学习笔记1--基础

    一.安装 1.安装 composer create-project laravel/laravel=v5.5.28 laravel 2.测试 配置nginx根目录为laravel/public,并且美 ...

  6. python爬虫框架—Scrapy安装及创建项目

    linux版本安装 pip3 install scrapy 安装完成 windows版本安装 pip install wheel 下载twisted,网址:http://www.lfd.uci.edu ...

  7. Linux虚拟机安装学习笔记

    一.Linux系统的安装1.VMwaer虚拟机的安装使用 官方下载软件地址:www.vmwaer.com 安装的虚拟机可以与现实的计算机进行通信 安装虚拟主机可以随意定制硬件安装配置建议: CPU:1 ...

  8. 网易2018校招 合唱 DP

      时间限制:2秒 空间限制:131072K 小Q和牛博士合唱一首歌曲,这首歌曲由n个音调组成,每个音调由一个正整数表示.对于每个音调要么由小Q演唱要么由牛博士演唱,对于一系列音调演唱的难度等于所有相 ...

  9. POJ 3723 Conscription【最小生成树】

    题意: 征用一些男生和女生,每个应都要给10000元,但是如果某个男生和女生之间有关系,则给的钱数为10000减去相应的亲密度,征集一个士兵时一次关系只能使用一次. 分析: kruskal求最小生成树 ...

  10. mysql计算两个日期之间的天数

    MYSQL自带函数计算给定的两个日期的间隔天数   有两个途径可获得   1.利用TO_DAYS函数   select to_days(now()) - to_days('20120512')   2 ...