码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-01-26 00:08:21      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:acm   数学   

链接: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

不解释,代码:

//zoj 2818  poj 3100

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
    double b,n;
    while(cin>>b>>n&&b&&n)
    {
        int a=(int )pow(b,1/n);
        //cout<<pow(a,n)<<endl;
        if(b-pow(a,n)<pow(a+1,n)-b) cout<<a<<endl;
        else cout<<a+1<<endl;
    }
    return 0;
}


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

标签:acm   数学   

原文地址:http://blog.csdn.net/u013050857/article/details/43125517

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!