zoukankan      html  css  js  c++  java
  • POJ 3100:Root of the Problem

    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
    ", 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
    ", high);
            else printf("%d
    ", low);
        }
        return 0;
    }

  • 相关阅读:
    ListBox的数据绑定
    GridView中加入新行方法
    一个事务的例子
    用sql语句查询从N条到M条的记录
    用户注册表中日期输入的解决方案
    对分页控件进行分页的封装
    我的触发器
    缓存DataSet以提高性能
    网站访问统计在Global.asax中的配置
    给表格控件绑定数据库内容的封装
  • 原文地址:https://www.cnblogs.com/im0qianqian/p/5989582.html
Copyright © 2011-2022 走看看