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=ceil(tmp);            //向上取整
		if(B-pow(p,N)>pow(q,N)-B)
			cout<<q<<endl;
		else
			cout<<p<<endl;
	}
    return 0;
}
时间: 2024-11-06 03:55:33

HDU ACM 2740 Root of the Problem 简单数学题的相关文章

hdu 2368 Alfredo&#39;s Pizza Restaurant(简单数学题)

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2368 题目很简单,但是比较恶心,用sqrt WA到死也不过,不用秒过: 忍不住吐槽一下; Problem Description Traditionally after the Local Contest, judges and contestants go to their favourite restaurant,

POJ 3100 &amp; ZOJ 2818 &amp; 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

HDU ACM 1057 A New Growth Industry 简单模拟

题意:给一个天数N,求20*20方阵内细菌的变化情况.每次变化加上一个d[k],d数组有给定的16个数.k是某个格子它本身加上它上下左右的四个数. 简单模拟题. 分析: #include<iostream> using namespace std; int dir[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; char den[]=".!X#"; int D[16]; int map[20][20],tmp[20][20]; void Fun() {

杭电 HDU ACM 1898 Sempr == The Best Problem Solver?

Sempr == The Best Problem Solver? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1438    Accepted Submission(s): 940 Problem Description As is known to all, Sempr(Liangjing Wang) had solved mo

HDU ACM 1010 Tempter of the Bone -&gt;简单搜索

分析:搜索题,注意剪枝. #include<iostream> using namespace std; int dfs(int si,int sj,int ei,int ej,int mt); char map[8][8]; int m,n,fa; int main() { int t,i,j,wall,sti,stj,eni,enj; while(cin>>n>>m>>t &&(n||m||t)) { wall=0; fa=0; for(

HDU 1282 回文数猜想(简单数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1282 Problem Description 一个正整数,如果从左向右读(称之为正序数)和从右向左读(称之为倒序数)是一样的,这样的数就叫回文数.任取一个正整数,如果不是回文数,将该数与他的倒序数相加,若其和不是回文数,则重复上述步骤,一直到获得回文数为止.例如:68变成154(68+86),再变成605(154+451),最后变成1111(605+506),而1111是回文数.于是有数学家提出一个

计蒜客 30990 - An Olympian Math Problem - [简单数学题][2018ICPC南京网络预赛A题]

题目链接:https://nanti.jisuanke.com/t/30990 Alice, a student of grade 6, is thinking about an Olympian Math problem, but she feels so despair that she cries. And her classmate, Bob, has no idea about the problem. Thus he wants you to help him. The proble

HDU 6467 简单数学题 【递推公式 &amp;&amp; O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 308    Accepted Submission(s): 150 Problem Description 已知 F(n)=∑i=1n(i×∑j=inCij) 求 F(n) m

hdu 1016 Prime Ring Problem (简单DFS)

Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25700    Accepted Submission(s): 11453 Problem Description A ring is compose of n circles as shown in diagram. Put natural numb