POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)

题目链接:

POJ:http://poj.org/problem?id=3100

ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1818

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2740

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

Mid-Central USA 2006

题意:

给定整数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;
}
时间: 2024-12-29 09:17:40

POJ 3100 & ZOJ 2818 & HDU 2740 Root of the Problem(数学)的相关文章

poj 3100 &amp;&amp; zoj 2818 ( Root of the Problem ) (睡前一水)

链接:click here 题意: 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. .给你B和N,求个整数A使得A^n最接近B

POJ 2777 &amp;&amp; ZOJ 1610 &amp;&amp;HDU 1698 --线段树--区间更新

直接将这3题 放一起了  今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 -- 区间更新的话 分为 增减 或者 修改 主要就是个 laze 标记 就是延迟更新 对于区间更新的写法 一般是有2种 其一 仔细划分到每个细小的区间    另一 粗略划分 反正 ==我的代码里会给出2种写法 看自己喜好 hdu 1 //线段树 成段更新 ---> 替换 根结点的查询 2 3 #i

POJ 3653 &amp; ZOJ 2935 &amp; HDU 2722 Here We Go(relians) Again(最短路dijstra)

题目链接: PKU:http://poj.org/problem?id=3653 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1934 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2722 Description The Gorelians are a warlike race that travel the universe conquering new world

POJ 3654 &amp; ZOJ 2936 &amp; HDU 2723 Electronic Document Security(模拟)

题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2936 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2723 Description The Tyrell corporation uses a state-of-the-art electronic document system th

POJ 3652 &amp; ZOJ 2934 &amp; HDU 2721 Persistent Bits(数学 进制)

题目链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1933 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2721 Description WhatNext Software creates sequence generators that they hope will produce fair

HDU ACM 2740 Root of the Problem 简单数学题

题意:求A,使得A^N最接近B. 分析:A=B^(1/n),对其上下取整,在各取N次幂,取最接近B的. #include<iostream> #include<cmath> using namespace std; int main() { int B,N,p,q; double tmp; while(cin>>B>>N && (B||N)) { tmp=pow(1.0*B,1.0/N); p=floor(tmp); //向下取整 q=cei

HDU 1116 || POJ 1386 || ZOJ 2016 Play on Words (欧拉回路+并查集)

题目链接 题意 : 有很多门,每个门上有很多磁盘,每个盘上一个单词,必须重新排列磁盘使得每个单词的第一个字母与前一个单词的最后一个字母相同.给你一组单词问能不能排成上述形式. 思路 :把每个单词看成有首字母指向尾字母的有向边,每个字母看成一个点,题中要求等效于判断图中是否存在一条路径经过每一条一次且仅一次,就是有向欧拉通路.统计个顶点的出入度,如果每个点的出入度都相同,那就是欧拉回路,如果有两个奇数度,那就是欧拉通路,除此之外,都不能满足要求.还有别忘了判断是否连通,此时用到并查集,图中所有的边

zoj 2818 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

ZOJ 2562 HDU 4228 反素数

反素数: 对于任何正整数x,起约数的个数记做g(x).例如g(1)=1,g(6)=4. 如果某个正整数x满足:对于任意i(0<i<x),都有g(i)<g(x),则称x为反素数. ZOJ 2562 反素数 因为写了POJ 2886的线段树,然后里面有反素数,以前没遇到过,所以先搞这两题普及一下知识再说. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm&